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

Always getting invalid response error for hash with Rails and jbuilder #304

Open
robinvdvleuten opened this issue Apr 12, 2021 · 2 comments

Comments

@robinvdvleuten
Copy link

I am setting up the middleware like this in my config/application.rb;

if Rails.env.development? || Rails.env.test?
  config.middleware.use Committee::Middleware::RequestValidation, 
	schema_path: 'docs/schema-bundled.yml',
	params_key: 'action_dispatch.request.request_parameters'
  config.middleware.use Committee::Middleware::ResponseValidation, 
	schema_path: 'docs/schema-bundled.yml',
	raise: true
end

Now whenever I render anything from my controllers, like;

def doorkeeper_forbidden_render_options(*)
  { json: { error: { code: 'forbidden', message: 'This action is outside the authorized scopes' } } }
end

I always receive a Committee:InvalidResponse error;

Committee::InvalidResponse: #/components/responses/forbidden/content/application~1json/schema expected , but received Hash: {"error"=>{"code"=>"forbidden", "message"=>"This action is outside the authorized scopes"}}

Where the schema definitions looks like this;

openapi: 3.0.0

paths:
  '/api/v1/accounts/{account_id}':
    get:
      operationId: get_account
      summary: Retrieve an existing acocunt
      description: >
        To show information about an account, send a GET request to
        `/api/v1/accounts/$ACCOUNT_ID`.
      tags:
        - Accounts
      parameters:
        - $ref: '#/components/parameters/account_id'
      responses:
        '401':
          $ref: '#/components/responses/unauthorized'

components:
  parameters:
    account_id:
      in: path
      name: account_id
      description: A unique identifier for an account.
      required: true
      schema:
        type: string
        format: uuid
      example: acf19357-d974-4843-9525-e98426ad5346
  
  schemas:
    error:
      type: object
      properties:
        code:
          type: string
          description: >
            A short identifier corresponding to the HTTP status code returned.
            For example, the identifier for a response returning a 404 status code
            would be "not_found."
          example: not_found
        message:
          type: string
          description: >
            A message providing additional information about the error,
            including details to help resolve it when possible.
          example: The resource you were accessing could not be found.
        request_id:
          type: string
          format: uuid
          description: |
            Optionally, some endpoints may include a request ID that should be
            provided when reporting bugs or opening support tickets to help
            identify the issue.
          example: 4d9d8375-3c56-4925-a3e7-eb137fed17e9
      required:
        - code
        - message

  responses:
    forbidden:
      description: Forbidden.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                $ref: '#/components/schemas/error'
          example:
            error:
              code: forbidden
              message: Forbidden to authenticate you.

Am I missing maybe some configuration value?

@robinvdvleuten
Copy link
Author

So apparently this has something to do spring caching the yaml definitions. When I run spring stop and run the tests again, it works 🤷‍♂️

@ota42y
Copy link
Member

ota42y commented Apr 25, 2021

What was the procedure that caused the problem?
For example, if you rewrite only the YAML file, the ruby ​​file will not be changed, so the spring doesn't reload config.

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