How to annotate array of objects response in Swagger
Use @ArraySchema instead of plain @Schema to define input or output data for array types.
Use @ArraySchema instead of plain @Schema to define input or output data for array types.
OpenAPI 3.1 OpenAPI 3.1 uses the latest JSON Schema, and the recommended way to annotate individual enum values in JSON Schema is to use oneOf+const instead of enum. This way you can specify both custom names (title) and descriptions for enum values. Severity: type: integer oneOf: – title: HIGH const: 2 description: An urgent problem … Read more
For anyone using Swashbuckle with ASP.NET, you can use the following code to have the $ref construct put under the allOf (just like the : // do this wherever you are calling AddSwaggerGen() ArgBuilder.Services.AddSwaggerGen(opts => { opts.UseAllOfToExtendReferenceSchemas(); // add this line. }); Now if you have a model with two properties of the same type, … Read more
The solution that worked for me was to declare in @ApiProperty() the type with arrow function, like below: @Entity() export class Job { . . . @ManyToOne(type => Customer, customer => customer.jobs) @ApiProperty({ type: () => Customer }) customer: Customer; }
Okay, so based on the comments above, you want the following schema: { “definitions”: { “user”: { “type”: “object”, “required”: [ “name” ], “properties”: { “name”: { “type”: “string” }, “address”: { “type”: “array”, “items”: { “$ref”: “#/definitions/address” } } } }, “address”: { “type”: “object”, “properties”: { “type”: { “type”: “string”, “enum”: [ “home”, … Read more
With the latest Swashbuckle, or better said at least the Swashbuckle.AspNetCore variant which I’m using, the Description field for parameters can now be displayed correctly as output. It does require the following conditions to be met: XML comments must be enabled and configured with Swagger Parameters should be explicitly decorated with either [FromRoute], [FromQuery], [FromBody] … Read more
I think enums can be defined only as object literals. Checkout this example it seems to explain quite well with an example. https://community.smartbear.com/t5/Swagger-Open-Source-Tools/Enum-of-defined-objects/m-p/198117/highlight/true#M988
responses: 200: description: Returns PDF schema: type: file Out of the options you gave, that’s the right option. Also, make sure to use produces: [application/pdf] If it fails for you, make sure you use the latest version of the editor. There was a bug related to the file type that was recently resolved.
Instead of using the JAR, you can also use https://generator.swagger.io to generate the SDKs (Java, Ruby, PHP, etc) online without installing anything. Here is an example: curl -X POST -H “content-type:application/json” -d ‘{“swaggerUrl”:”http://petstore.swagger.io/v2/swagger.json”}’ https://generator.swagger.io/api/gen/clients/java and here is a sample response: {“code”:”1445940806041″,”link”:”https://generator.swagger.io/api/gen/download/1445940806041″} You can then download the zipped SDK from the link. For more options on … Read more
@ApiImplicitParams and @ApiImplicitParam should do the trick: @GET @Produces(“application/json”) @ApiImplicitParams({ @ApiImplicitParam(name = “Authorization”, value = “Authorization token”, required = true, dataType = “string”, paramType = “header”) }) public String getUser(@PathParam(“username”) String userName) { … } From the documentation: You may wish you describe operation parameters manually. This can be for various reasons, for example: Using … Read more