4

I generate a Java class from a YAML file describing the model with openapi-generator-maven-plugin.

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>4.3.1</version>
    <executions>
      <execution>
        <id>document-10-service</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <inputSpec>${project.basedir}/src/openapi/server/v1.0/documents-1.0.yaml</inputSpec>
          <output>${project.build.directory}/generated-sources/document-10-service</output>
          <generateApis>true</generateApis>
          <generateApiTests>false</generateApiTests>
          <generateModelTests>false</generateModelTests>
          <generateApiDocumentation>false</generateApiDocumentation>
          <generateModelDocumentation>false</generateModelDocumentation>
          <generateSupportingFiles>true</generateSupportingFiles>
          <apiPackage>com.siemens.spice.documents.generated.api</apiPackage>
          <modelPackage>com.siemens.spice.documents.generated.model</modelPackage>
          <invokerPackage>com.siemens.spice.documents.generated</invokerPackage>
          <generatorName>spring</generatorName>
          <skipOverwrite>false</skipOverwrite>
          <configOptions>
            <sourceFolder>server</sourceFolder>
            <supportingFiles>ApiUtil.java</supportingFiles>
            <library>spring-boot</library>
            <dateLibrary>java8</dateLibrary>
            <interfaceOnly>true</interfaceOnly>
            <useBeanValidation>true</useBeanValidation>
            <hideGenerationTimestamp>true</hideGenerationTimestamp>
          </configOptions>
        </configuration>
      </execution>

I have the following model described in the YAML file:

 Document:
required:
  - documentMetaData
  - documentContent
type: "object"
properties:
  documentMetaData:
    $ref: "#/definitions/DocumentMetaData"
    description: "Document type information"
  documentContent:
    type: string
    format: byte
    description: "Base64 encoded document content"

This generates the following class which is ok:

public class DownloadDocument   {
  @JsonProperty("documentMetaData")
  private DocumentMetaData documentMetaData;

  @JsonProperty("documentContent")
  private byte[] documentContent;
}

But when entering the swagger-ui.html page and trying to get the documentation by click on the link:

enter image description here

it looks like this:

"DownloadDocument": {
            "required": [
                "documentContent",
                "documentMetaData"
            ],
            "type": "object",
            "properties": {
                "documentMetaData": {
                    "$ref": "#/components/schemas/DocumentMetaData"
                },
                "documentContent": {
                    **"type": "array",
                    "items": {
                        "type": "string",
                        "format": "byte"
                    }**
                }

The document content which is a byte[] is documented as an array of byte[] and when using this description in other app to generate an API client it generates a List<byte[]>.

I would expect the following format also in the OpenApi Specification/Description:

documentContent:
    type: string
    format: byte
    description: "Base64 encoded document content"

Can you please advice if this is a bug or if not how can be resolved?

2
  • 1
    I am using the following versions: <springdoc-openapi-ui.version>1.5.9</springdoc-openapi-ui.version> <swagger-annotations.version>1.5.22</swagger-annotations.version>and <artifactId>openapi-generator-maven-plugin</artifactId> <version>4.3.1</version> Commented Jun 4, 2021 at 6:32
  • did I understand properly that you generate java api using openapi spec, and then openapi-ui generates openapi spec using java api? O_o. BTW, there was a bug in openapi-ui String with format byte (base64) is being an array of strings and not a string #1559 Commented Sep 1, 2022 at 16:30

1 Answer 1

2

If you have generated Java classes from a YAML file the Swagger UI should generate the origin YAML/JSON file.

Known Issues

There are several issues for OpenAPI Tools:

There are also several issues for SpringFox:

There are also issues for springdoc-openapi:

Other implementations with issues:

Known work-arounds

Related questions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.