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

"format" in path parameter #8

Closed
natsuokawai opened this issue Jul 31, 2020 · 5 comments
Closed

"format" in path parameter #8

natsuokawai opened this issue Jul 31, 2020 · 5 comments

Comments

@natsuokawai
Copy link
Contributor

Hello. Thank you for such a useful gem!

I have a problem.

When I make a request in json format, the path parameter should contain a key named format, so the generated OpenAPI schema has a key named format as a path parameter.
So the generated OpenAPI schema has a format field in the path parameters list.
Since I don't use this field as a variable in the actual path, the error occurs because there is no format in the URL when loaded by swagger-editor.

Semantic error at paths./api/v1/xxxxx.get.parameters.0.name
Path parameter "format" must have the corresponding {format} segment in the "/api/v1/xxxxx" path

Is there a problem with skipping the format in lib/rspec/openapi/schema_builder.rb:39 in the same way as the action and controller?

@k0kubun
Copy link
Collaborator

k0kubun commented Jul 31, 2020

It's hard to understand the problem without code. Could you provide a request spec and/or a repository which reproduces the issue, and expected OpenAPI schema generated by that?

@natsuokawai
Copy link
Contributor Author

natsuokawai commented Jul 31, 2020

Here is the repository.
https://github.com/natsuokawai/rspec-openapi-sample

Step to reproduce:

$ git clone git@github.com:natsuokawai/rspec-openapi-sample.git
$ cd rspec-openapi-sample
$ bundle install
$ rm doc/openapi.yaml
$ OPENAPI=1 bundle exec rspec spec/requests/api/posts_spec.rb

In this repository, I configure routes file like this:

Rails.application.routes.draw do
  namespace :api, format: 'json' do
    resources :posts, only: %i(index)
  end
end

openapi.yaml that produced is as follows:

...
paths:
  "/api/posts":
    get:
      summary: 'api/posts #index'
      parameters:
      - name: format
        in: path
        required: true
        schema:
          type: string
        example: json
      - name: title
        in: query
        schema:
          type: string
        example: f
...

The generated file has a format in parameters field, but I expect is:

openapi: 3.0.3
info:
  title: rspec-openapi-sample
paths:
  "/api/posts":
    get:
      summary: 'api/posts #index'
      parameters:
      - name: format
        in: path
        required: true
        schema:
          type: string
        example: json
      - name: title
        in: query
        schema:
          type: string
        example: f
      responses:
        '200':
          description: get posts
          content:
            application/json:
              schema:
                type: object
                properties:
                  posts:
                    type: array
                    items:
                      type: object
                      properties:
                        title:
                          type: string
              example:
                posts:
                - title: foo

@k0kubun
Copy link
Collaborator

k0kubun commented Jul 31, 2020

Thanks for providing the repository.

The generated file has a format in parameters field, but I expect is:

...
      parameters:
      - name: format
        in: path
        required: true
        schema:
          type: string
        example: json
...

What you expect also includes format, but I guess you intended to remove it?

@k0kubun k0kubun closed this as completed in ef5235d Aug 1, 2020
@k0kubun
Copy link
Collaborator

k0kubun commented Aug 1, 2020

I pushed a new version v0.3.2 which I believe fixes the issue. Could you try that?

@natsuokawai
Copy link
Contributor Author

I have tried the new version and confirmed that this problem is no longer occurring. Thank you so much!

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

No branches or pull requests

2 participants