question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in mockserver with query param when uses $ref

See original GitHub issue

When you want to create a mockserver with multiple examples based on a query param. If the query param is a $ ref it doesn’t work correctly.

Example good: / resources:

    get:
      tags: [examples]
      summary: Get resources by query
      description: Get a list of resources by query
      operationId: queryOp
      parameters:
        - name: resourceType
          in: query
          description: Get a list of resources by type
          schema:
            type: string
            enum: [standard, premium]
          examples:
            standard_example:
              value: 'standard'
            premium_example:
              value: 'premium'
      responses:
        '200':
          description: List of resources
          content:
            application / json:
              schema:
                properties:
                  yam:
                    type: string
                  resourceType:
                    type: string
                    enum: [standard, premium]
              examples:
                standard_example:
                  value:
                    - name: 'Resource One'
                      resourceType: 'standard'
                premium_example:
                  value:
                    - name: 'Resource Two'
                      resourceType: 'premium'
                all_example:
                  value:
                    - name: 'Resource One'
                      resourceType: 'standard'
                    - name: 'Resource Two'
                      resourceType: 'premium'

Example bad: / resources:

    get:
      tags: [examples]
      summary: Get resources by query
      description: Get a list of resources by query
      operationId: queryOp
      parameters:
        - $ ref: '# / components / parameters / resourceTypeQueryParam'
      responses:
        '200':
          description: List of resources
          content:
            application / json:
              schema:
                properties:
                  yam:
                    type: string
                  resourceType:
                    type: string
                    enum: [standard, premium]
              examples:
                standard_example:
                  value:
                    - name: 'Resource One'
                      resourceType: 'standard'
                premium_example:
                  value:
                    - name: 'Resource Two'
                      resourceType: 'premium'
                all_example:
                  value:
                    - name: 'Resource One'
                      resourceType: 'standard'
                    - name: 'Resource Two'
                      resourceType: 'premium'

Thanks for all.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jgonzalezcloudappicommented, Jun 22, 2021

Hi lbroudoux,

I’will provide you a complete example:

openapi: "3.0.0"
info:
  title: API-Template2
  version: 1.0.0

servers:
  - url: https://dev-api.openfinance.es/api-name/v1
    description: Development server
  - url: https://api.openfinance.es/api-name/v1
    description: Production server
tags:
  - name: examples
    description: 'Examples for Microcks.io'

paths:
  # Example with only one query parameter
  /resources:
    get:
      tags: [examples]
      summary: Get resources by query
      description: Get a list of resources by query
      operationId: queryOp
      parameters:
        - name: resourceType
          in: query
          description: Get a list of resources by type
          schema:
            type: string
            enum:  [standard, premium]
          examples:
            standard_example:
              value: 'standard'
            premium_example:
              value: 'premium'
      responses:
        '200':
          description: List of resources
          content:
            application/json:
              schema:
                properties:
                  name:
                    type: string
                  resourceType:
                    type: string
                    enum: [standard, premium]
              examples:
                standard_example:
                  value:
                    - name: 'Resource One'
                      resourceType: 'standard'
                premium_example:
                  value:
                    - name: 'Resource Two'
                      resourceType: 'premium'
                all_example:
                  value:
                    - name: 'Resource One'
                      resourceType: 'standard'
                    - name: 'Resource Two'
                      resourceType: 'premium'
  # Example with problem in URI_PARAMS
  /accounts:
    get:
      tags: [examples]
      summary: Get resources by multiple query params
      description: Get a list of resources by multiple query params
      operationId: dobleQueryOp
      parameters:
        - $ref: '#/components/parameters/levelQueryParam'
      responses:
        '200':
          description: List of accounts
          content:
            application/json:
              schema:
                properties:
                  accountID:
                    type: string
                  level:
                    type: string
                    enum: [bronze, golden]
              examples:
                bronze_example:
                  value:
                    - accountID: AC001
                      level: bronze
                      region: national
                    - accountID: AC002
                      level: bronze
                      region: international
                golden_example:
                  value:
                    - accountID: AC003
                      level: golden
                      region: national
                    - accountID: AC004
                      level: golden
                      region: international
                all_example:
                  value:
                    - accountID: AC001
                      level: bronze
                      region: national
                    - accountID: AC002
                      level: bronze
                      region: international
                    - accountID: AC003
                      level: golden
                      region: national
                    - accountID: AC004
                      level: golden
                      region: international
                
components:
  parameters:
    levelQueryParam:
      name: level
      in: query
      description: Account level
      schema:
        type: string
        enum: [bronze, golden]
      examples:
        bronze_example:
          value: 'bronze'
        golden_example:
          value: 'golden'
        all_example:
          value: 'all'

Check in the resource accounts please, uri_params not works correctly

Thanks for all

0reactions
lbroudouxcommented, Jun 22, 2021

It should be available now in latest container image. It will be included into 1.3.0 release I hope on next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Expectations - MockServer
A request properties matcher matches requests using one or more of the following properties: method - property matcher; path - property matcher; path...
Read more >
java - MockRestServiceServer how to verify only request path ...
In the test method I want to verify that the correct endpoint path and query params (name particularly) are used in API call....
Read more >
jamesdbloom/mockserver - Gitter
I'm looking for a way using which I can define 2 expectations, one with Query parameters and other without it (for same Method...
Read more >
Mocking - Apollo GraphQL Docs
Mock your GraphQL data based on a schema. ... New in Apollo Server 4: Apollo Server 4 removes both the mocks and mockEntireSchema...
Read more >
Interface Mockttp
const mockServer = require('mockttp'). ... Call .start() to set up a server on a random port, use . ... url. url: string. Defined...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found