Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] OAS3 server URL/host not parsed #3399

Closed
4 of 6 tasks
MartinDelille opened this issue Jul 19, 2019 · 4 comments
Closed
4 of 6 tasks

[BUG] OAS3 server URL/host not parsed #3399

MartinDelille opened this issue Jul 19, 2019 · 4 comments

Comments

@MartinDelille
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)

Hi,

After a long time working on other subject, I come back to openapi-generator because I seriously consider using it for my project.

Description

I'm encountering a issue when generating a Qt5 client where there is a URL generation error: the protocol is not added when building the request:

OAIDefaultApi::OAIDefaultApi() : basePath("/v1"),
    host("api.myapp.com"),
    timeout(0){

}

...

void
OAIDefaultApi::findContactById(const QString& contact_id) {
    QString fullPath;
    fullPath.append(this->host).append(this->basePath).append("/contact/{contactId}");
    ...
}

This code generate the following url: api.myapp.com/v1/contact/{contactId} instead of https://api.myapp.com/v1/contact/{contactId}.

There is a easy way to fix it is to call defaultApi.setHost("https://api.myapp.com") before findContactById but I guess it might broke in the long term.

openapi-generator version

4.0.3

OpenAPI declaration file content or url
openapi: 3.0.1
servers:
  - url: 'https://api.myapp.com/v1'
info:
  description: This is myapp.com API.
  version: 1.0.0
  title: myapp.com
components:
  schemas:
    Contact:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: string
        name:
          type: string
paths:
  /contact/{contactId}:
    get:
      operationId: findContactById
      parameters:
        - name: contactId
          in: path
          schema:
            type: string
          required: true
      responses:
        '200':
          description: An contact object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Contact'
Command line used for generation
openapi-generator generate -i api.yaml -g cpp-qt5-client
Steps to reproduce

After generating the client, try to call the OAIDefaultApi::findContactById() method and see how the URL is badly formed.

Related issues/PRs

None

Suggest a fix

I'll be happy to fix it but I'd like to have some direction how we should handle this case:

  • Do we agree that here the host is api.myapp.com and not https://api.myapp.com?
  • How do handle the https protocol ?

Ping @ravinikam @stkrwork @etherealjoy

@auto-labeler
Copy link

auto-labeler bot commented Jul 19, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@etherealjoy
Copy link
Contributor

etherealjoy commented Jul 21, 2019

In OAS 2.0

host: api.example.com
basePath: /v1
schemes:
  - https

In OAS 3.0

servers:
  - url: '{protocol}://api.example.com'
    variables:
      protocol:
        enum:
          - http
          - https
        default: https

I think we should use the one parsed by the base utils. If an issue exist in the parsing of the server variables it is to be fixed in the base util classes

How do handle the https protocol

This is handled automatically by the Qt client when the scheme is https. Qt will use the host cert chain to verify the server. When a custom cert is to be used the Qt method is to be used below

QSslSocket::addDefaultCaCertificate
Certificate is read from the pem file.

@MartinDelille
Copy link
Contributor Author

MartinDelille commented Jul 22, 2019

After looking at the template, it seems that the scheme is handled: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache#L13

It looks like it is not parsed for OAS 3.0

@etherealjoy etherealjoy changed the title [BUG] Qt client server URL/host mismatch [BUG] OAS3 server URL/host not parsed Jul 26, 2019
@etherealjoy
Copy link
Contributor

Fixed with #4429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants