Defining conditional attributes in OpenAPI
I need to define a request for a searching service in JSON. Request can have either geographical coordinates (longitude and latitude) or postal code. Either one must be present. If longitude is present, then latitude is required and vice versa. If both are omitted, postal code must be present. If geo coordinates present, postal code is optional (will be ignored if present). I am having trouble defining such request in swagger editor. If someone can help me, I will appreciate it greatly. We are using v.3.0.3 and the swagger file will be used to generate client code.SolvedHow 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" } }] } ] }SolvedAllow yaml to define enum with different name and value
A common practice is to use enum to define coded persistence values such as: Status: type: string enum: - name: ABANDONED value: A - name: ISSUED value: I However this generates a JSON object as the value ABANDONED_A("{name: ABANDONED, value: A}") Is this not possible with OAS3?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.yml9.3KViews0likes5Commentsswagger ui freezing in expanding POST or PUT method
we added swagger to our project that developed withWeb Api core, the problem is freezing swagger ui in expanding PUT/POST methods (when use complex objects . GET methods works correctly) . we don NOT use Dto models and all APIs work with Domain Models directly. I think its because of many relationships or recursive relationship between models.but itsimpossible for us to change application structure . Is there any solution to solve this issue without big changes in projectSolvedSwagger api to generate HTML from yaml
I am trying to generate HTML from YAML file using .https://generator3.swagger.io/api/generateenpoint but if my yaml file has markdown text it does not seem to support and the html file which is generated does not parse markdown text . How can I parse markdown text ?Best way to combine multiple OpenAPI specifications
ExLibris' products Alma and Primo have comprehensive REST APIs, and similar to many vendors they divide these into multiple API Specifications. This is a problem for me because: (a) I will need to run swagger-codegen multiple times (b) I will need to handcraft the deserialization process. Even there I run into problems because there could be multiple inline body classes. (c) Or, I will need to combine the different APIs I need by hand into one OpenAPI specification. Online, I found a blog post that suggested using the npm package speccy to combine them -https://blog.runscope.com/posts/how-to-merge-openapi-definition-files. But I get some messages about deprecated packages. Is there any capability in OpenAPI itself to combine specifications beyond referencing schemas? Is there a more maintained tool that does the combining I am looking for?5.3KViews0likes0CommentsC# Enum generation - underlying int values do not match the original enum
I created an enum on my server with integer values set manually rather than the default increment up from 0 public enum UserType { Anonymous = 0, Customer = 10, Technician = 21, Manager = 25, Primary = 30 } I am using AspNetCore.App 2.2.0 and swashbuckle aspnetcore 4.0.1 to generate my CSharp API client The generated enum in the c sharp api client (using NSwag Studio for windows v 13.2.3.0) looks like this - the underlying integer values do not match the original enum. [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.5.0 (Newtonsoft.Json v11.0.0.0)")] public enum UserType { [System.Runtime.Serialization.EnumMember(Value = @"Anonymous")] Anonymous = 0, [System.Runtime.Serialization.EnumMember(Value = @"Customer")] Customer = 1, [System.Runtime.Serialization.EnumMember(Value = @"Technician")] Technician = 2, [System.Runtime.Serialization.EnumMember(Value = @"Manager")] Manager = 3, [System.Runtime.Serialization.EnumMember(Value = @"Primary")] Primary = 4, } This creates a problem for me client side as there are situations where I need to know the integer value. I am looking for a solution where I can avoid writing converters every time I want to know the integer value on the client side. Option 1: Is there an option I am missing in either NSwag Studio or in .net configuration (my Startup.Cs config is below for reference) where I can force the generated enums to get the same integer values as the original enum? Option 2: Alternatively if not, both my client and my server have access to the same original enum via a shared class library. Is there a way to get the generated api client to use the actual original enums in the apiclient.cs rather than generate its own? Reference: The enums part of my swagger generation code in Startup.Cs looks like this services.AddJsonOptions(options => { options. SerializerSettings.Converters.Add(new StringEnumConverter()); ....services.AddSwaggerGen(setup => { setup.SwaggerDoc("v1", new Info { Title = AppConst.SwaggerTitle, Version = "v1" }); setup.UseReferencedDefinitionsForEnums(); ... other stuff... } Matching SO question if you want some rephttps://stackoverflow.com/questions/60222469/swagger-c-sharp-enum-generation-underlying-int-values-do-not-match-the-origina