Home > Mobile >  Whitelabel Error Page : How to export or open api doc in YAML file with maven
Whitelabel Error Page : How to export or open api doc in YAML file with maven

Time:03-09

I have integrated swagger UI in java using maven, through which I am able to test my REST springBoot API at swagger UI and also able to see the open API doc in json format using the URL: http://localhost:8091/v2/api-docs?group=public-api . But my requirement is to get that doc in yaml format, for which I am hitting below URL but getting error

http://localhost:8091/v3/api-docs.yaml

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Mar 09 13:27:55 IST 2022
There was an unexpected error (type=Internal Server Error, status=500).
tried to access method com.fasterxml.jackson.databind.introspect.AnnotatedMember.getAllAnnotations()Lcom/fasterxml/jackson/databind/introspect/AnnotationMap; from class io.swagger.v3.core.jackson.ModelResolver 

The entries in POM.xml is

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.javainuse</groupId>
    <artifactId>springboot-swagger-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webmvc-core</artifactId>
            <version>1.6.6</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

My swagger UI

enter image description here

CodePudding user response:

After do some changes in POM.xml , able to download the doc in .yaml file.

URL to download the doc in .yaml file is : http://localhost:8091/v3/api-docs.yaml

And updated POM.xml is

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.javainuse</groupId>
    <artifactId>springboot-swagger-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.4</version>

    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webmvc-core</artifactId>
            <version>1.6.6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

The sample generated .yaml file

openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
- url: http://localhost:8099
  description: Generated server url
paths:
  /api/javainuse2:
    post:
      tags:
      - product-controller
      operationId: saveProduct
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Product'
        required: true
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: string
  /api/javainuse:
    get:
      tags:
      - hello-controller
      operationId: sayHello
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: string
  /api/javainuse1:
    get:
      tags:
      - product-controller
      operationId: getProduct
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Product'
  /swagger-resources:
    get:
      tags:
      - api-resource-controller
      operationId: swaggerResources_1
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SwaggerResource'
    put:
      tags:
      - api-resource-controller
      operationId: swaggerResources
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SwaggerResource'
    post:
      tags:
      - api-resource-controller
      operationId: swaggerResources_3
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SwaggerResource'
    delete:
      tags:
      - api-resource-controller
      operationId: swaggerResources_4
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SwaggerResource'
    options:
      tags:
      - api-resource-controller
      operationId: swaggerResources_2
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SwaggerResource'
    head:
      tags:
      - api-resource-controller
      operationId: swaggerResources_6
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SwaggerResource'
    patch:
      tags:
      - api-resource-controller
      operationId: swaggerResources_5
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SwaggerResource'
  /swagger-resources/configuration/ui:
    get:
      tags:
      - api-resource-controller
      operationId: uiConfiguration_1
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/UiConfiguration'
    put:
      tags:
      - api-resource-controller
      operationId: uiConfiguration
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/UiConfiguration'
    post:
      tags:
      - api-resource-controller
      operationId: uiConfiguration_3
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/UiConfiguration'
    delete:
      tags:
      - api-resource-controller
      operationId: uiConfiguration_4
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/UiConfiguration'
    options:
      tags:
      - api-resource-controller
      operationId: uiConfiguration_2
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/UiConfiguration'
    head:
      tags:
      - api-resource-controller
      operationId: uiConfiguration_6
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/UiConfiguration'
    patch:
      tags:
      - api-resource-controller
      operationId: uiConfiguration_5
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/UiConfiguration'
  /swagger-resources/configuration/security:
    get:
      tags:
      - api-resource-controller
      operationId: securityConfiguration_1
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SecurityConfiguration'
    put:
      tags:
      - api-resource-controller
      operationId: securityConfiguration
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SecurityConfiguration'
    post:
      tags:
      - api-resource-controller
      operationId: securityConfiguration_3
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SecurityConfiguration'
    delete:
      tags:
      - api-resource-controller
      operationId: securityConfiguration_4
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SecurityConfiguration'
    options:
      tags:
      - api-resource-controller
      operationId: securityConfiguration_2
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SecurityConfiguration'
    head:
      tags:
      - api-resource-controller
      operationId: securityConfiguration_6
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SecurityConfiguration'
    patch:
      tags:
      - api-resource-controller
      operationId: securityConfiguration_5
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SecurityConfiguration'
components:
  schemas:
    Product:
      type: object
      properties:
        id:
          type: integer
          format: int32
        pname:
          type: string
        batchno:
          type: string
        price:
          type: number
          format: double
        noofproduct:
          type: integer
          format: int32
    SwaggerResource:
      type: object
      properties:
        name:
          type: string
        url:
          type: string
        swaggerVersion:
          type: string
        location:
          type: string
          deprecated: true
    UiConfiguration:
      type: object
      properties:
        deepLinking:
          type: boolean
        displayOperationId:
          type: boolean
        defaultModelsExpandDepth:
          type: integer
          format: int32
        defaultModelExpandDepth:
          type: integer
          format: int32
        defaultModelRendering:
          type: string
          enum:
          - example
          - model
        displayRequestDuration:
          type: boolean
        docExpansion:
          type: string
          enum:
          - none
          - list
          - full
        filter:
          type: object
        maxDisplayedTags:
          type: integer
          format: int32
        operationsSorter:
          type: string
          enum:
          - alpha
          - method
        showExtensions:
          type: boolean
        tagsSorter:
          type: string
          enum:
          - alpha
        validatorUrl:
          type: string
        apisSorter:
          type: string
          deprecated: true
        jsonEditor:
          type: boolean
          deprecated: true
        showRequestHeaders:
          type: boolean
          deprecated: true
        supportedSubmitMethods:
          type: array
          items:
            type: string
    SecurityConfiguration:
      type: object
      properties:
        apiKey:
          type: string
          deprecated: true
        apiKeyVehicle:
          type: string
          deprecated: true
        apiKeyName:
          type: string
          deprecated: true
        clientId:
          type: string
        clientSecret:
          type: string
        realm:
          type: string
        appName:
          type: string
        scopeSeparator:
          type: string
        additionalQueryStringParams:
          type: object
          additionalProperties:
            type: object
        useBasicAuthenticationWithAccessCodeGrant:
          type: boolean

CodePudding user response:

There is a typo in your URL it should be http://localhost:8091/v2/api-docs.yaml

I tested from my side and it works for me and it downloads the yaml file

enter image description here

  • Related