Skip to content

Provide a way to not auto-fill examples for certain parameters #686

Closed

Description

@majoshi1

We have some optional fields with examples. But, they still getting populated with first value from examples. The default can be set only inside examples. But, that also shows up in examples. So, is it possible to allow setting default outside?
Current: To show empty default for non-required fields.

{
	"parameters": [{
			"name": "someName",
			"required": false,
			"schema": {},
			"examples": {
				"default": false,
				"example1": {
					"summary": "Item1",
					"value": "10"
				}
			}
		}
	]
}

Proposed: Set default inside schema, so that it does not appear in examples.

{
	"parameters": [{
			"name": "someName",
			"required": false,
			"schema": {
				"default": false
			},				
			"examples": {
				"example1": {
					"summary": "Item1",
					"value": "10"
				}
			}
		}
	]
}

Activity

  1. mrin9 commented on Mar 9, 2022

    @mrin9
    Collaborator

    I am not sure whats the ask here. Can you explain with some screen shot may be, what are you getting and what do you intent to have

  2. majoshi1 commented on Mar 9, 2022

    @majoshi1
    Author

    Sorry for any confusion. This is actually a defect that optional fields are pre-populated with first value from examples. Can provide example if needed.

  3. hrvoj3e commented on Mar 15, 2022

    @hrvoj3e

    I have the same problem.

    I would like to somehow hint in yaml schema that field should not be populated from example.
    Examples are great and I can click on them to populate field with defaults.
    Maybe some extension field x-example-fill: false or something?

    get:
      summary: content search
      operationId: seachContent
      tags:
        - content-search
      parameters:
        - in: query
          name: search
          examples:
            a:
              value: my example 1
            b:
              value: "*"
          schema:
            type: string
          description: term to search (use "*" to show all)
        - in: query
          name: id
          example: my-id
          schema:
            type: string
        - in: query
          name: db
          example: ccc
          schema:
            type: string
            enum:
             - aaa
             - bbb
             - ccc
             - ddd
      responses:
        200:
          description: OK
          content:
            application/json: {}
        400:
          $ref: "../response/400.yaml"

    image

  4. mrin9 commented on Mar 22, 2022

    @mrin9
    Collaborator

    Maybe some extension field x-example-fill: false or something?

    I think thats a good suggestion.
    added to our queue

  5. changed the title [-]Allow setting default outside examples[/-] [+]Provide a way to not auto-fill examples for certain parameters[/+] on Mar 22, 2022
  6. mrin9 commented on Mar 26, 2022

    @mrin9
    Collaborator

    use vendor extension x-example-fill : no for each parameter to indicate if it should be filled
    you may also use RapiDoc attribute fill-request-fields-with-example = true/false to indicate no autofilling of example for the entire spec

    get:
      summary: content search
      operationId: seachContent
      tags:
        - content-search
      parameters:
        - in: query
          name: search
          example: 'my-search-string'
          x-fill-example:  no    # <--- vendor extension
          schema:
            type: string
          description: term to search (use "*" to show all)
        - in: query
          name: id
          example: my-id
          schema:
            type: string
  7. added a commit that references this issue on Nov 5, 2024
    4397b35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions