openapi.yml examples do not appear in swagger

17 Views Asked by At

I am working with apigenerator, I have a yml and according to https://editor-next.swagger.io/ everything is correct, the examples appear and everything is fine. But when I launch my project in swagger the examples do not appear. Also in the example of the result of the path get it appears not only in code 200 but also in errors 400 500. In the login, the examples do not appear in the corresponding fields nor in the definition part of the DTOs

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.4</version>
        <relativePath />
    </parent>
    <groupId>com.inditex</groupId>
    <artifactId>Inditex-proyecto</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Inditex-proyecto</name>
    <description>Prueba inditex</description>
    <properties>
        <java.version>17</java.version>
        <org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <springdoc>2.4.0</springdoc>
        <auth0>4.4.0</auth0>
        <openapitools>7.4.0</openapitools>
        <lombok>1.18.32</lombok>
        <projectlombok>0.2.0</projectlombok>
        <jsonwebtoken>0.12.5</jsonwebtoken>
    </properties>
    <dependencies>
        <!-- Spring Boot Starter Dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Springdoc OpenAPI Starter -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>${springdoc}</version>
        </dependency>
        <!-- Test integracion -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- Spring Boot Starter Dependencies -->
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${org.mapstruct.version}</version>
        </dependency>
        <!-- H2 Database -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- Compilacion en caliente -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>${jsonwebtoken}</version>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- Spring Boot Maven Plugin -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <!-- OpenAPI Generator Maven Plugin -->
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>${openapitools}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>
                                ${project.basedir}/src/main/resources/openapi.yml</inputSpec>
                            <generatorName>spring</generatorName>
                            <generateModelDocumentation>true</generateModelDocumentation>
                            <configOptions>
                                <documentationProvider>springdoc</documentationProvider>
                                <modelPackage>com.inditex.aplicacion.dto</modelPackage>
                                <apiPackage>com.inditex.presentacion.api</apiPackage>
                                <openApiNullable>false</openApiNullable>
                                <interfaceOnly>true</interfaceOnly>
                                <useSpringBoot3>true</useSpringBoot3>
                                <useJakartaEe>true</useJakartaEe>
                                <annotationLibrary>swagger2</annotationLibrary>
                                <dateLibrary>java8</dateLibrary>
                                <useJakartaEe>true</useJakartaEe>
                                <example>json</example>
                                <additionalModelTypeAnnotations>
                                    @lombok.NoArgsConstructor
                                    @lombok.AllArgsConstructor
                                    @lombok.Builder
                                    @lombok.Data
                                </additionalModelTypeAnnotations>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok}</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>${projectlombok}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

this is my openapi.yml

openapi: 3.0.3
info:
  title: Inditex API
  description: Información de stock de Inditex
  contact:
    name: Carlos Diaz
    email: [email protected]
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 3.0.0
servers:
  - url: http://localhost:8080/inditex.html
tags:
  - name: Prices
    description: stock en tienda
  - name: Login
    description: Operacion de login
security:
  - BearerToken: []
paths:
  /prices/{brandId}/{productId}:
    get:
      tags:
        - Prices
      summary: Obtener la tarifa a aplicar por ID de empresa, producto y fecha que se desea consultar.
      description: Obtener la tarifa a aplicar teniendo en cuenta el ID de la empresa del grupo, el id del producto y la fecha que nos interesa.
      operationId: obtenerTarifaAplicar
      parameters:
        - in: path
          name: brandId
          description: ID de la tienda dentro del grupo Inditex
          required: true
          schema:
            type: string
          example: '1'
        - in: path
          name: productId
          description: ID del producto buscado
          required: true
          schema:
            type: string
          example: '1565'
        - in: query
          name: fechaAConsultar
          description: Fecha que queremos consultar
          required: true
          schema:
            type: string
            format: date-time
          example: '2023-05-01T14:30:00Z'
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PriceDTO'
              example:
                brandId: '1'
                productId: '1565'
                consultationDate: '2023-05-01T14:30:00Z'
                precio: 19.99
                curr: EUR
        '400':
          description: Error en la URL
        '204':
          description: No encontrado
        '422':
          description: Base de datos no accesible
        '500':
          description: Internal Server Error
  /autenticacion/login:
    post:
      tags:
        - Login
      summary: Crear un token de autenticación
      description: Autentica un usuario y genera un token JWT.
      operationId: AutenticacionLoginPost
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JwtRequest'
            example:
              identificator: 'Pedro69'
              password: '1234'
      responses:
        '201':
          description: Token creado
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JwtResponse'
              example:
                jwttoken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Sm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5'
        '204':
          description: Credenciales inválidas
        '400':
          description: Error en la URL
        '500':
          description: Base de datos no accesible
components:
  schemas:
    PriceDTO:
      type: object
      properties:
        brandId:
          description: id de la empresa del grupo
          type: string
          example: '1'
        productId:
          description: id del producto
          type: string
          example: '1565'
        consultationDate:
          description: fecha que queremos consultar
          type: string
          format: date-time
          example: '2023-05-01T14:30:00Z'
        precio:
          description: precio a aplicar
          type: number
          example: 19.99
        curr:
          description: moneda
          type: string
          example: EUR
    JwtResponse:
      type: object
      properties:
        jwttoken:
          type: string
          description: token de seguridad
    JwtRequest:
      type: object
      properties:
        identificator:
          type: string
          description: Username
          example: 'Pedro69'
        password:
          type: string
          description: clave para el login
          example: '1234'
0

There are 0 best solutions below