How to swagger annotate multipart form data with resteasy?
I'm attempting to annotate an endpoint in resteasy that is a multipart form upload. One part is expected to be the stream of a file, and the other part is json metadata about the file. Because we're using resteasy, the method parameter is a MultipartFormDataInput, which isn't very helpful for describing what the endpoint actually needs for input. I've currently got annotations as follows: @POST @Path("/") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Upload a new image and associated metadata", description = "Long form description saying whatever we want", parameters = { @Parameter(name = "file", description = "image file", required = true, style = ParameterStyle.FORM, content = { @Content(mediaType = "application/pdf", schema = @Schema(type = "string", format = "binary")), @Content(mediaType = "image/png", schema = @Schema(type = "string", format = "binary")) }), @Parameter(name = "metadata", description = "image metadata", required = true, style = ParameterStyle.FORM, content = { @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MetadataRequest.class)) }) }, responses = { @ApiResponse(responseCode = "200", description = "The UUID of the newly uploaded image"), @ApiResponse(responseCode = "403", description = "The provided credentials are insufficient to see this resource."), @ApiResponse(responseCode = "415", description = "The provided file type is not supported"), @ApiResponse(responseCode = "500", description = "We messed up. Please let us know so we can fix it ASAP.") }) public PublicUploadResponse upload(@Parameter(hidden = true) MultipartFormDataInput form) { for which swagger generates the following json "/v1/images" : { "post" : { "summary" : "Upload a new image and associated metadata", "description" : "Long form description saying whatever we want", "operationId" : "upload", "responses" : { "200" : { "description" : "The UUID of the newly uploaded image" }, "403" : { "description" : "The provided credentials are insufficient to see this resource." }, "415" : { "description" : "The provided file type is not supported" }, "500" : { "description" : "We messed up. Please let us know so we can fix it ASAP." } } } }, As you can see, the parameter annotations are completely ignored. I've tried moving the parameter annotations to the method, and that doesn't change anything. We're using lastest swagger-core (2.0.6). I just can't figure out why they are being ignored. Any help or suggestions would be appreciated.How to express an array in a swagger definition
How can I express an array of objects in a defition. Here's the sample json { "resourceType": "Patient", "extension": [{ "url": "http://hl7.org/fhir/StructureDefinition/us-core-race", "extension": [{ "url": "ombCategory", "valueCoding": { "system": "http://hl7.org/fhir/v3/Race", "code": "2106-3", "display": "White" } }] }, { "url": "http://hl7.org/fhir/StructureDefinition/us-core-ethnicity", "extension": [{ "url": "ombCategory", "valueCoding": { "system": "http://hl7.org/fhir/v3/Ethnicity", "code": "2135-2", "display": "Hispanic or Latino" } }] } ] }SolvedHow to specify request headers for a post method
I have a method like the following in my spring boot based web service. I am trying to generate open api spec for the following using swagger core annotations. I would like to add all the acceptable headers to the spec file. I am wondering how to do that with annotations. @POST @Produces({ MediaType.APPLICATION_JSON + ";charset=UTF-8" }) @Operation(description = "This is my api") //1. overall Header annotations public Response post(@Context HttpHeaders headers, //2. header parameters @Context UriInfo uriInfo, @RequestBody MyRequest myRequest) { I am wondering where to put the annotations to list the headers. Also how to list all the headers. I saw many examples of headers in ApiResponse, but i am trying to add request header. Thanks SriniAdditional properties not allowed: oneOf
Hi everyone ! It's been few days that I'm trying to create a "clean" configuration with swagger, but swagger-cli doesn't validate some of it. To explain the context, first of all I use swagger-cli with swagger-ui, and I bundle the following output used by swagger-ui with swagger-cli : "choices": { "type": "array", "description": "The choices", "items": { "anyOf": [ { "$ref": "../../../choice/choice.boolean.output.json" }, { "$ref": "../../../choice/choice.integer.output.json" }, { "$ref": "../../../choice/choice.text.output.json" } ] } } And everytime I'm trying to validate the schema with the following command : swagger-cli validate api-description.yaml I have the same error : Additional properties not allowed: oneOf at #/properties/.../items/properties/choices I try lot of combinations with docs : https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/ https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/ https://swagger.io/docs/specification/data-models/data-types/ https://swagger.io/docs/specification/describing-responses/ And I notice something weird about that, that I'm able to bundle it with the same package swagger-cli and display part of it in the swagger-ui "Example value" section : But in the model view I have an empty model : Do you know why ? I really need help :(Swagger $ref gives "Could not resolve reference: undefined undefined"
so I'm trying to separate the objects that we give in the responses body into separate yaml, or json, files and it gives all the time the same error. Errors Resolver error at paths./api/thing.get.responses.200.content.application/json.schema.$ref Could not resolve reference: undefined undefined This is my Main.yaml file: openapi: 3.0.0 info: version: '0.0.1' title: 'thing-services' license: name: MIT tags: - name: thingReturn description: ''" paths: /api/thing: get: tags: - thingReturn description: 'Recovers things' responses: '200': description: 'Returns a list of things.' content: application/json: schema: $ref: 'ThingList.yaml#components/schemas/ThingList' '204': description: No Content. There was no content found. This is my ThingList.yaml file: components: schemas: ThingList: type: array items: $ref: 'Thing.yaml#/components/schemas/Thing' This is my Thing.yaml file: components: schemas: Thing: type: object properties: id: type: string property1: type: integer format: int32 property2: type: integer format: int32 Lets just say that everything is in the same folder (the original idea is to have the objects in a "object-schemas" folder), it doesn't work either. If I put the objects inside the Main.yaml file with the "#/components/schemas/...", it works fine but it beats the purpose of having everything organized in separate files. I don't know if I'm overlooking something. Any help is appreciated.Swagger OpenAPI Code Gen "oneOf" : How to generate correct class file?
TLDR: Swagger offers a feature named 'oneOf'. The resulting java classes created do not seem to be correct. Details: I am creating the spring/java server side rest api code. And when I send a request. The request object is not parsed correctly. The following error is printed in the console. JSON parse error: Could not resolve subtype of [simple type, class com.model.Issuer]: missing type id property 'type' (for POJO property 'issuer'); nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class com.Issuer]: missing type id property 'type' (for POJO property 'issuer')\n at [Source: (PushbackInputStream); line: 3, column: 15] (through reference chain: com.IssueCredentialRequest[\"credential\"]->com.Credential[\"issuer\"]) The reason seem to be that the generated class does not have subtypes: package com.sphereon.vdp.vc.service.model; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ }) public interface OneOfIssuer { } There is another class which is generated correctly package com.sphereon.vdp.vc.service.model; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = VerifyPresentationRequest.class, name = "VerifyPresentationRequest"), @JsonSubTypes.Type(value = ProoflessVerifyPresentationRequest.class, name = "ProoflessVerifyPresentationRequest") }) public interface OneOfpresentationsVerifyBody { } Can someone point to what am I missing? <plugin> <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>3.0.33</version> <dependencies> <dependency> <groupId>com.github.jknack</groupId> <artifactId>handlebars</artifactId> <version>4.3.0</version> </dependency> </dependencies> <executions> <execution> <id>vc-rest-api-issuer-source-generation</id> <goals> <goal>generate</goal> </goals> <phase>generate-sources</phase> <configuration> <inputSpec>${pom.basedir}/specifications/issuer.yml</inputSpec> <language>spring</language> <apiPackage>com.company.vdp.vc.service.api</apiPackage> <modelPackage>com.company.vdp.vc.service.model</modelPackage> <artifactVersion>${project.version}</artifactVersion> <generateModels>true</generateModels> <generateApis>true</generateApis> <generateModelDocumentation>true</generateModelDocumentation> <generateSupportingFiles>true</generateSupportingFiles> <verbose>${openapi-codegen-verbose}</verbose> <output>${project.basedir}/target/generated-sources/java/api</output> <ignoreFileOverride>${project.basedir}/target/generated-sources/java/api/.swagger-codegen-ignore</ignoreFileOverride> <configOptions> <delegatePattern>true</delegatePattern> <dateLibrary>java8</dateLibrary> <useTags>true</useTags> </configOptions> </configuration> </execution> <execution> <id>vc-rest-api-verifier-source-generation</id> <goals> <goal>generate</goal> </goals> <phase>generate-sources</phase> <configuration> <inputSpec>${pom.basedir}/specifications/verifier.yml</inputSpec> <language>spring</language> <apiPackage>com.company.vdp.vc.service.api</apiPackage> <modelPackage>com.company.vdp.vc.service.model</modelPackage> <artifactVersion>${project.version}</artifactVersion> <generateModels>true</generateModels> <generateApis>true</generateApis> <generateModelDocumentation>true</generateModelDocumentation> <generateSupportingFiles>true</generateSupportingFiles> <verbose>${openapi-codegen-verbose}</verbose> <output>${project.basedir}/target/generated-sources/java/api</output> <ignoreFileOverride>${project.basedir}/target/generated-sources/java/api/.swagger-codegen-ignore</ignoreFileOverride> <configOptions> <delegatePattern>true</delegatePattern> <dateLibrary>java8</dateLibrary> <useTags>true</useTags> </configOptions> </configuration> </execution> </executions> </plugin> Following is the spec file that I am using without editing. https://github.com/w3c-ccg/vc-api/blob/main/components/Issuer.yml https://github.com/w3c-ccg/vc-api/blob/main/verifier.yml https://github.com/w3c-ccg/vc-api/blob/main/components/Issuer.yml https://github.com/w3c-ccg/vc-api/blob/main/verifier.ymlArray null values
Hello, Is it possible to define an array that can not contain null? I'm compiling it to Java with Open API 3.0 f.e for this example A: type: array minItems: 1 items: $ref: "#/components/schemas/B" B: type: string pattern: ^[a-z]+$ I consider [null] or ["abc",null] invalid Thanks in advanceSolvedHow to suppress requestBody generation in OpenAPI spec using swagger-maven-plugin
I'm using the swagger-maven-plugin in a Java application with an old school servlet implementation. I'm trying to follow the examples here:https://github.com/swagger-api/swagger-samples/,but unfortunately this one:https://github.com/swagger-api/swagger-samples/blob/master/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.javawhich is the closest match, uses the 1.x version of swagger.core, not 2.x. I found other examples that sort of work (see what I did below), except that it generates an almost 950 line requestBody element in the openapi.yaml doc for this endpoint. Why does it do that? Is there a way to suppress that? Below is the maven import and the code snippet: <groupId>io.swagger.core.v3</groupId> <artifactId>swagger-maven-plugin</artifactId> <version>2.1.2</version> The code with annotations is: @Path("/Test00020") public class Test00020 extends HttpServlet { @Override @GET @Operation ( summary = "Ask something, get something back.", parameters = { @Parameter(in = ParameterIn.QUERY, name="TestParam00020", required = true ) } ) public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... Thanks, DaveSolved6.9KViews0likes11CommentsOpenApi 3 specify all Query Parameters using a single Schema ref with Marshmallow Plugin
Hi, I have a python project and I am using Marshmallow to define my schemas for input, output and query parameters. I am now trying to create my OpenAPI 3 docs using apispec library and I'm running into an issue with rendering my query parameters. I have this snippet in my doc declaration of my route whereListQueryParameters contains all my query parameters (like page, sortby, etc..) It fails to render unless I add `name`. But according tohttps://apispec.readthedocs.io/en/latest/_modules/apispec/ext/marshmallow/schema_resolver.html#SchemaResolver.resolve_parametersand it's docs https://apispec.readthedocs.io/en/latest/api_ext.html#apispec.ext.marshmallow.schema_resolver.SchemaResolver.resolve_parameters, it should work. parameters: - customerId - in: query name: queryParams schema: $ref: '#/components/schemas/ListQueryParameters' In the final generation of my openapi spec documentation the query param section it shows queryParams as a JSON object for input which has all my listed parameters. However I want the final docs generated to be a name value pair of these properties, not a nested object. I can manually specify these as a workaround, but don't want to maintain this list of properties as some apis have 50+ query parameters parameters: - customerId - in: query name: sortby description: Sort by description - in: query name: page description: Current Page to view schema: type: int ... Is there an easy way to resolve accomplish this without doing my workaround? Thanks, ArtSolved6.2KViews0likes2Comments