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.yml8.7KViews0likes5CommentsArray 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.8KViews0likes11CommentsOAS 3.0.3 request schema for an empty JSON body
I am attempting to create an OAS schema for an empty JSON body: { } I am trying to get the documentation to show an empty JSON body, and have that autogenerated. The API defines this as a POST (yes, it ought to be a GET, the design of the API is in some respects sub-optimal) request, and expects the open/close bracket, and nothing else. I've tried … content: application/json: { } … but that doesn't work (it just shows nothing in the request body), and everything else I've tried is invalid. Would appreciate any assistance on this. I have not been able to find any examples or even similar questions (maybe I’m looking in the wrong place?). Any assistance would be greatly appreciated!Solved6.1KViews0likes2Comments