Skip to content

Conversation

@fehguy
Copy link
Contributor

@fehguy fehguy commented Oct 16, 2015

Adds example values for query, header, form, and path params. The goal is to differentiate between the default value, which is intended to be "what the server will do by default if no value is passed". The example construct is not supported in the 2.0 specification so it is being exposed using x-example for scalar parameters and x-examples for body parameters.

For example:

@ApiOperation(value = "test")
@GET
@Path("external/info")
public void queryExample(@ApiParam(value = "test",
        example = "a,b,c") @QueryParam("tenantId") ArrayList<String> tenantId) {
    return;
}

This is represented as:

{
  "name" : "tenantId",
  "in" : "query",
  "description" : "test",
  "required" : false,
  "type" : "a,b,c",
  "items" : {
    "type" : "string"
  },
  "x-example" : "a,b,c"
}

will allow the string array to have an example value of a, b, c

Likewise for a post body:

@ApiOperation(value = "test")
@POST
@Path("external/info")
public void postTest(@ApiParam(value = "test",
        examples = @Example(value = {
                @ExampleProperty(mediaType="application/json", value="[\"a\",\"b\"]")
        })) ArrayList<String> tenantId) {
    return;
}

This is represented as:

{
  "in" : "body",
  "name" : "body",
  "description" : "test",
  "required" : false,
  "schema" : {
    "type" : "array",
    "items" : {
      "type" : "string"
    }
  },
  "x-examples" : {
    "application/json" : "[\"a\",\"b\"]"
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used by the code.

@fehguy
Copy link
Contributor Author

fehguy commented Oct 17, 2015

I've addressed the two comments from before.

@fehguy
Copy link
Contributor Author

fehguy commented Oct 19, 2015

  • Need to make sure the example value has the correct type, currently always string.

@fehguy fehguy mentioned this pull request Oct 19, 2015
4 tasks
fehguy added a commit that referenced this pull request Oct 19, 2015
@fehguy fehguy merged commit baadf78 into master Oct 19, 2015
@webron webron deleted the feature/example-values branch August 19, 2016 20:36
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

Successfully merging this pull request may close these issues.

3 participants