Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger Codegen basePath is being ignored

I'm trying to generate some web services definitions using Swagger Codegen » 2.2.1

All configs are working and the classes are generate correctly by my .yaml definitions.

Why the property basePath is being ignored?


My @RestController generate using only paths definition:

https://springboot-base-save-return.appdes.xnet/saveBackendReturn

Expected (using basePath and paths definitions):

https://springboot-base-save-return.appdes.xnet/v1/saveBackendReturn

What am I doing wrong? Did I forget something?


My .yaml contract:

swagger: '2.0'
info:
  description: My Project
  version: 1.0.0
  title: Save Backend Return
host: springboot-base-save-return.appdes.xnet
basePath: /v1
tags:
  - name: saveBackendReturn
    description: Save Backend Return
schemes:
  - https
paths:
  /saveBackendReturn:
    post:
      tags:
        - saveBackendReturn
      summary: Save Backend Return
      description: My Project
      operationId: saveBackendReturn
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: body
          description: My Project
          required: true
          schema:
            $ref: '#/definitions/saveBackendReturnRequest'
      responses:
        '200':
          description: Ok
          schema:
            $ref: '#/definitions/saveBackendReturnResponse'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '500':
          description: Internal Server Error
          schema:
            $ref: '#/definitions/Error'
      security:
        - basicAuth: []
like image 319
ℛɑƒæĿᴿᴹᴿ Avatar asked Jan 26 '20 12:01

ℛɑƒæĿᴿᴹᴿ


People also ask

What is basePath swagger?

basePath is the URL prefix for all API paths, relative to the host root. It must start with a leading slash / . If basePath is not specified, it defaults to / , that is, all paths start at the host root. Valid base paths: /v2.

What is swagger codegen CLI?

Swagger Codegen is an open source project which allows generation of API client libraries (SDK generation), server stubs, and documentation automatically from an OpenAPI Specification.

What is the default swagger UI URL?

By default, Swagger UI is accessible at /q/swagger-ui . The value / is not allowed as it blocks the application from serving anything else. A value prefixed with '/' makes it absolute and not relative. Once your application is started, you can go to http://localhost:8080/q/swagger-ui and play with your API.

What is API base path?

The base path is the initial URL segment of the API, and does not include the host name or any additional segments for paths or operations. It is shared by all operations in the API.


1 Answers

Searching more about this, I found the issue.

It's a bug fixed by HugoMario (commit referenced on 2 Dec 2019)

  • [Spring] Fixes #5244 Include basePath @RequestMapping in Spring API template

  • Release on master (#8131) » v2.4.12 / v2.4.11

And following Helen suggestion, I update my Swagger Codegen:

  • From » 2.2.1 » old release (Aug 07, 2016)

  • To » 2.4.12 » current stable release (Jan 15, 2020)

Summary: » It's a bug of an outdated version » Now works fine!


Maven dependecy for swagger-codegen-maven-plugin:

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.4.12</version>
</dependency>

Maven Central Repository (check new releases):

  • https://mvnrepository.com/artifact/io.swagger/swagger-codegen-maven-plugin

Update Maven Project (Eclipse shortcut F5) and make a clean build:

mvn clean verify 
mvn install

Reference:

  • https://github.com/swagger-api/swagger-codegen
like image 56
ℛɑƒæĿᴿᴹᴿ Avatar answered Nov 04 '22 01:11

ℛɑƒæĿᴿᴹᴿ