Add Upload button for OpenAPI 2.0 file as Octet-Stream
Context I am using OpenAPI ver 2.0 I have API which consumesapplication/octet-stream(JavaInputStream) Issue In OpenAPI ver 2.0 I can only set input type asmultipart/form-data(link) to have upload button. When I have applied this solution for my swagger: <code> "consumes": [ "multipart/form-data" ], "produces": [ "application/json" ], "parameters": [ { "in": "formData", "name": "messageFile", "description": "Description...", "required": true, "type": "file" } ] </code> I am getting following error:Unsupported Media Typeafter sending a file - itis normal due to my API wants octet-stream. Question Is it possible to have upload button using OpenAPI ver 2.0 andapplication/octet-streamlike: If no, then what will be better solution / workaround for this?Solved3.6KViews0likes3CommentsHow do I properly define an example for a nullable property in OpenAPI 3?
I am using OpenAPI and openapi-generator-maven-plugin with Spring Boot. I'm trying to create an example object in my response. I've followed the suggestions of several different web pages, especially this one: https://swagger.io/docs/specification/adding-examples/ But no matter what I try, I can't get the example data to show up correctly. Here the object that should be in a request: Period: type: object required: - startDate - endDate properties: startDate: type: string format: date nullable: true example: "2021-01-01" endDate: type: string format: date nullable: true example: "2030-01-01" CreateInstancesRequest: type: object required: - id properties: id: $ref: '#/components/schemas/Id' period: allOf: - $ref: '#/components/schemas/Period' But I get not what I want: I expect something like this: { "id": "some-id", "period": { "endDate": "2020-01-01", "startDate": "2022-01-01" } } But maybe I am wrong because generated java code for the Period class: I thinkpresentproperty from actual example came fromorg.openapitools.jackson.nullable.JsonNullableclass. Can you help me, please?Swagger show file content via @ExampleProperty annotation
I am using swagger 3.0.0-Snapshot to create documentation for my Spring Boot application. My maven dependencies are <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>3.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>3.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-spring-webmvc</artifactId> <version>3.0.0-SNAPSHOT</version> </dependency> My swagger config class is as simple as possible: @Configuration @EnableSwagger2WebMvc public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .useDefaultResponseMessages(false) .select() .apis(RequestHandlerSelectors.basePackage("com.mycompany.cs")) .paths(PathSelectors.any()) .build() .pathMapping("/") .useDefaultResponseMessages(false); } And my controller method has the following annotation: @ApiOperation(value = "Hello world", httpMethod = "POST") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", examples = @Example(value = @ExampleProperty(mediaType = "application/json", value = exampleValue))) }) It is working and shows in Swagger UI "Example Value" field value that has constant string exampleValue that is private static String. The question is how to pass the content of json file that is in resources folder to @ExampleProperty value? I tried to read file content in static block and pass it to initialize final String with it, but then the compiler says that "Attribute value has to be constant". The content of json file must be shown in example field in Swagger UI.2.3KViews0likes0Comments[JAVA] [JAX-RS] Server InvalidDefinitionException: Cannot construct instance by using oneOf
Hi Smartbear Community, I have the following swagger.yaml that uses theoneOfkeyword and I used the latest Swagger codegen tools (3.0.22) to create a server stub for JAX-RS Jersey. openapi: 3.0.0 info: version: 0.0.1 title: Polymorphism example description: '' paths: /animal: post: summary: Create a new animal requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/Animal' responses: '201': description: Created components: schemas: Animal: properties: name: type: string props: oneOf: - $ref: '#/components/schemas/Fish' - $ref: '#/components/schemas/Dog' Fish: type: object properties: depth: type: integer Dog: type: object properties: country: type: string I am trying to post the following example object: { "name":"Foo", "props":{ "country":"Bar" } } But this results in the following exception: javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `io.swagger.model.OneOfAnimalProps` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 30] (through reference chain: io.swagger.model.Animal["props"]) at org.glassfish.jersey.servlet.WebComponent.serviceImpl (WebComponent.java:432) at org.glassfish.jersey.servlet.WebComponent.service (WebComponent.java:370) at org.glassfish.jersey.servlet.ServletContainer.service (ServletContainer.java:389) at org.glassfish.jersey.servlet.ServletContainer.service (ServletContainer.java:342) at org.glassfish.jersey.servlet.ServletContainer.service (ServletContainer.java:229) at org.eclipse.jetty.servlet.ServletHolder.handle (ServletHolder.java:808) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1669) at io.swagger.api.ApiOriginFilter.doFilter (ApiOriginFilter.java:15) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (ServletHandler.java:1652) at org.eclipse.jetty.servlet.ServletHandler.doHandle (ServletHandler.java:585) at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle (SecurityHandler.java:577) at org.eclipse.jetty.server.session.SessionHandler.doHandle (SessionHandler.java:223) at org.eclipse.jetty.server.handler.ContextHandler.doHandle (ContextHandler.java:1127) at org.eclipse.jetty.servlet.ServletHandler.doScope (ServletHandler.java:515) at org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:185) at org.eclipse.jetty.server.handler.ContextHandler.doScope (ContextHandler.java:1061) at org.eclipse.jetty.server.handler.ScopedHandler.handle (ScopedHandler.java:141) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle (ContextHandlerCollection.java:215) at org.eclipse.jetty.server.handler.HandlerCollection.handle (HandlerCollection.java:110) at org.eclipse.jetty.server.handler.HandlerWrapper.handle (HandlerWrapper.java:97) at org.eclipse.jetty.server.Server.handle (Server.java:497) at org.eclipse.jetty.server.HttpChannel.handle (HttpChannel.java:310) at org.eclipse.jetty.server.HttpConnection.onFillable (HttpConnection.java:257) at org.eclipse.jetty.io.AbstractConnection$2.run (AbstractConnection.java:540) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:635) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run (QueuedThreadPool.java:555) at java.lang.Thread.run (Thread.java:748) Swagger-codegen version Swagger-codegen version: 3.0.22 Command line used for generation CLI command:java -jar swagger-codegen-cli.jar generate -i openapi.yaml -l jaxrs-jersey -o jaxrs-jersey/ Any advise how to fix this issue is much appreciated!1.6KViews0likes4CommentsIn eclipse IDE Java Client API for swagger is not getting generated.
Hi Team, 1.In my project I am implementing Swagger in Eclipse IDE, want to know what exactly is the Process of integrating swagger with eclipse IDE . I have tried as mentioned in the below link , but facing issue while doing Maven build. https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin 2.Swagger API Client is not getting generated in eclipse eventhough i have added theJar- Swagger-codegen-maven-plugin POM.xml. 3. can some one help in setting up Swagger API Client generation in Eclipse IDE for Java. ideally after doing the Maven install the basic client code should get generated which is not happening.1.5KViews0likes0CommentsJava code gen "incompatible types" generic list value
I am getting an error in java code gen for a map of String->String[] in java. The swagger source definition: DataMap: description: Provides a generic map of string->string additionalProperties: $ref: '#/components/schemas/StringArray' title: DataMap type: object StringArray: description: String array items: type: string title: StringArray type: array Results in java code: private Map<String, List<String>> dataMap = null; public RequestMetaData putDataMapItem(String key, List<String> dataMapItem) { if (this.dataMap == null) { this.dataMap = new HashMap<String, List>(); } this.dataMap.put(key, dataMapItem); return this; } This does not compile. It fails with error: incompatible types: HashMap<String,List> cannot be converted to Map<String,List<String>> This seems like a common definition structure. Has anyone seen this/resolved it?Support validation groups when reading Java annotations
Hi, I've got a Java Spring Boot project using swagger core v3 version 2.1.1 and springdoc openapi core version 1.1.49. We're using swagger annotations on our POJOs to generate our documentation, which is very useful - each field has a@Schema annotation, and swagger automatically reads the validation annotations (@NotNull, @Size, etc) to incorporate them into the documentation. My question deals with those validation annotations. In some cases, we're using validation groups (eg, @NotNull(groups = Create.class) ) to enable/disable annotations based on which endpoint is being used (eg, a field required to be Not Null on a POST might be allowed to be null on a PATCH.) Is there a way to get swagger to automatically detect those differences and populate them to the documentation? Currently, it's just reading the annotations and ignoring the validation groups. In the alternative, is it possible to override the automatically-detected annotations in-code? EDIT: The other use case we're hitting is trying to make certain fields hidden for some endpoints, but not for others. Is there a way to update the default implementation schema in that way?1.2KViews0likes0CommentsWhat does <*> symbol represent in json swagger?
I have a question in JSON swagger. May I know what does <*> symbol represent in JSON swagger? This is how the format looks like after I import the JSON swagger into the online editor. What does <*> actually mean? CrossCurrencyRequest{ items* { < * >: CurrencyPairRequest{ amount* number currencyPair* string decimalPlace integer($int32) } } } Below are the definitions from the swagger file. definitions: CrossCurrencyRequest: type: object required: - items properties: items: type: object additionalProperties: $ref: '#/definitions/CurrencyPairRequest' title: CrossCurrencyRequest I have the sample request as given below. How to make the request generates the "key1", "key2", etc? As it seems like not a predefined object from the swagger file. Sample request: { "items": { "key1": { "amount": 1000.123456789, "currencyPair": "USD-SGD", "decimalPlace": 5 }, "key2": { "amount": 1000.12345, "currencyPair": "USD-IDR" }, "key3": { "amount": 1000.12345, "currencyPair": "USD-ZNH" } } }SolvedSwagger in junit
From the swagger UI (https://petstore.swagger.io/?_ga=2.138463798.444042846.1559674010-1100161644.1559674010#/pet/addPet) I can make a call in introduced format by clicking "Try it out" button. It is great! But, is there a possibility to: - use swagger to generate http request objects in java in introduced format. For instance, I want make this call (https://petstore.swagger.io/?_ga=2.138463798.444042846.1559674010-1100161644.1559674010#/pet/findPetsByStatus) from the java test, providing a parametr status as an argument to some method, which will generate httpRequest or make a call and return httpResponse.Swagger Core 2.x OpeanAPI 3 Examples tied to Dataclass(variables)
I'd like to to add examples to my OpenAPI 3 Autogenerated Documentation which I generate with "io.swagger.core.v3.swagger-gradle-plugin" I didn't find a way to bind the example to the variable of my dataclass, like you could do with @ApiModelProperty for a swagger V2 file. All I found is @ExampleObject which you have to define for each response as a String. Am I missing something or is that the only way to add Examples to a swagger.v3 approach?