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

Add Open API document for OSB API #389

Merged
merged 18 commits into from
Jan 16, 2018

Conversation

n3wscott
Copy link
Contributor

@n3wscott n3wscott commented Dec 2, 2017

Relates to #160

Ready.

@cfdreddbot
Copy link

Hey n3wscott!

Thanks for submitting this pull request! I'm here to inform the recipients of the pull request that you and the commit authors have already signed the CLA.

@n3wscott n3wscott changed the title [WIP] Add Open API document for OSB API Add Open API document for OSB API Dec 4, 2017
Copy link

@rhodie27 rhodie27 left a comment

Choose a reason for hiding this comment

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

When validating I get:

Errors
Schema error at components.parameters['APIVersion']
should NOT have additional properties
additionalProperty: default, schema
Jump to line 379
Schema error at components.parameters['APIVersion'].in
should be equal to one of the allowed values
allowedValues: path, query, cookie
Jump to line 381

Also, as an FYI, this would be a breaking change for service authors that currently use the 2.12 swagger spec to generate code since you changed parameters and objects slightly. I'm not (necessarily) saying that's a problem.

I'll have more time to review next week.

@n3wscott
Copy link
Contributor Author

n3wscott commented Dec 5, 2017

@rhodie27 Yes, there is an open bug with swagger editor not pulling in parameters from components correctly. swagger-api/swagger-ui#3976 swagger-api/swagger-ui#3558

But I think what is in this PR is correct based on the Open API spec. The swagger UI works correctly.

I will double check the spec... I think I am correct and the tools have not caught up to the new stuff in 3.0.0. https://swagger.io/docs/specification/components/

@avade avade added this to the 2.14 milestone Dec 12, 2017
@fmui
Copy link
Member

fmui commented Dec 14, 2017

Here are some random nit-picking comments.

  • In the spec we several places with wording like this: "MUST be a non-empty string". "minLength: 1" should cover this.
  • In the schema definition Service -> properties -> requires, items should be an array of enums (syslog_drain, route_forwarding, volume_mount).
  • The schema of the status code '409' of 'PUT /v2/service_instances/{instance_id}' could be an Error, not an Object.
  • The status code '400' of 'PUT /v2/service_instances/{instance_id}/service_bindings/{binding_id}' is lacking a content definition.
  • The definitions of "route" and "*_url" properties and could be enhanced by "format: url".
  • The conventions for service and plan metadata are not in the spec, but we link to them from the spec. Should we do something similar here?

@n3wscott
Copy link
Contributor Author

@fmui

In the spec we several places with wording like this: "MUST be a non-empty string". "minLength: 1" should cover this.

I would vote for no validation in the first version of the swagger spec. It might be useful to not have the validation in to allow folks to poke at bad brokers. If we still want validation, could it be a followup exercise?

The schema of the status code '409' of 'PUT /v2/service_instances/{instance_id}' could be an Error, not an Object.

The spec says MAY for an error and expected to be {}:

| 409 Conflict | MUST be returned if a Service Instance with the same id already exists but with different attributes. The expected response body is `{}`, though the description field MAY be used to return a user-facing error message, as described in [Service Broker Errors](#service-broker-errors).|

The conventions for service and plan metadata are not in the spec, but we link to them from the spec. Should we do something similar here?

I opted to only use the spec.

I have updated based on feedback, adding the missing return types and enums, but I am hesitating to add more validation to the doc just because it is hard to know when to stop. I think it could be a valuable addition to the Open API document, but it is still possible to do as a followup and we could do it one resources

schema:
$ref: '#/components/schemas/ServiceInstanceUpdateRequest'
responses:
'200':
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 missing the operation field that is valid in the response of PATCH on Service Instances

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the spec, for PATCH it says this:

200 --> MUST be returned if the request's changes have been applied. The expected response body is {}.

So the spec does not say the operation field is allowed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@n3wscott I agree; operation shouldn't be returned here as a 200 implies the update has completed synchronously.

type: boolean
responses:
'200':
description: OK
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 missing the operation field that is valid in the response of DELETE on Service Instances

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@fmui
Copy link
Member

fmui commented Dec 19, 2017

So, what's the meaning of this excerpt:

| 409 Conflict | MUST be returned if a Service Instance with the same id already exists but with different attributes. The expected response body is {}, though the description field MAY be used to return a user-facing error message, as described in Service Broker Errors.|

  1. You can add a description, but you better shouldn't. The platform doesn't expect it.
  2. This a broker error, but you don't have to provide a description.

@n3wscott
Copy link
Contributor Author

@fmui it means that 409 must at least return {} and optionally return a service broker error.

@n3wscott
Copy link
Contributor Author

@avade thanks for the review! I will fix those missing return params up when I next get a chance.

Copy link
Contributor Author

@n3wscott n3wscott left a comment

Choose a reason for hiding this comment

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

Added AsyncOperation. @avade please remove conflict label.

type: boolean
responses:
'200':
description: OK
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

schema:
$ref: '#/components/schemas/ServiceInstanceUpdateRequest'
responses:
'200':
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor Author

@n3wscott n3wscott left a comment

Choose a reason for hiding this comment

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

Thanks a lot @mattmcneeney for the review!

Check out the new version with the updates here: Live

content:
application/json:
schema:
$ref: '#/components/schemas/AsyncOperation'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a mistake, AsyncOperation was suppose to be used for only the update, not the create.

content:
application/json:
schema:
$ref: '#/components/schemas/ServiceInstanceProvision'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true. My argument is it might not hurt anything to allow an optional field be defined in the Open API doc for the 201 case. the 200 and 202 cases are the same object.

content:
application/json:
schema:
$ref: '#/components/schemas/ServiceInstanceProvision'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 200 could apply to the sync or async cases.

content:
application/json:
schema:
$ref: '#/components/schemas/Object'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what the spec says:

400 -> MUST be returned if the request is malformed or missing mandatory data.

And then

Service Brokers can include a user-facing message in the description field;

I struggled with this TBH, the spec says some responses should {} some should be in the { "error":"" , "description":""} form and some it does not say. The line below the table says the quote above but it is not clear is that applies to all or some.

So I opted to define the response as Object at least, and where the spec calls it out, define the response as Error.

Perhaps this is something we update after the doc has some usage if it is not working for folks or is unclear.

schema:
$ref: '#/components/schemas/ServiceInstanceUpdateRequest'
responses:
'200':
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the spec, for PATCH it says this:

200 --> MUST be returned if the request's changes have been applied. The expected response body is {}.

So the spec does not say the operation field is allowed.

content:
application/json:
schema:
$ref: '#/components/schemas/Object'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made an issue to clear this up.

content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not how I read the spec.

I made an issue to clear this up.

The Error object has both fields optional.

- volume_mount
bindable:
type: boolean
metadata:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a bad idea. Added.

openapi.yaml Outdated
- service_id
properties:
context:
$ref: '#/components/schemas/Object'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

openapi.yaml Outdated
- plan_id
properties:
context:
$ref: '#/components/schemas/Object'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@mattmcneeney mattmcneeney left a comment

Choose a reason for hiding this comment

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

Thanks for the speedy turnaround @n3wscott 👏

content:
application/json:
schema:
$ref: '#/components/schemas/ServiceInstanceProvision'
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. I hadn't considered returning the id of a completed async operation (when a service instance has successfully been provisioned async).

content:
application/json:
schema:
$ref: '#/components/schemas/ServiceInstanceProvision'
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but that could make platform authors write logic to handle polling when they get a 201 which should never be used.

content:
application/json:
schema:
$ref: '#/components/schemas/AsyncOperation'
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

content:
application/json:
schema:
$ref: '#/components/schemas/Object'
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. If we can use this PR as an opportunity to clear up ambiguities in the spec, then I'd love for any error to be able to return the defined error object :)

schema:
$ref: '#/components/schemas/ServiceInstanceUpdateRequest'
responses:
'200':
Copy link
Contributor

Choose a reason for hiding this comment

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

@n3wscott I agree; operation shouldn't be returned here as a 200 implies the update has completed synchronously.

application/json:
schema:
$ref: '#/components/schemas/AsyncOperation'
'400':
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks!

application/json:
schema:
$ref: '#/components/schemas/AsyncOperation'
'400':
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

content:
application/json:
schema:
$ref: '#/components/schemas/Object'
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

content:
application/json:
schema:
$ref: '#/components/schemas/Object'
Copy link
Contributor

Choose a reason for hiding this comment

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

Tracking in #403

openapi.yaml Outdated
plan_id:
type: string
context:
$ref: '#/components/schemas/Object'
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you spot this one too @n3wscott ?

items:
$ref: '#/components/schemas/Service'

Service:
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this and all others need to include the type: object attribute, otherwise you're saying they can also be arrays or primitives. At least that's how it was in OpenAPI 2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch!

openapi.yaml Outdated
# This is the Open API interface for Open Service Broker API. Every attempt will
# be made to make the Open API version of OSB API accurately represent the
# written specification. If the spec and this document conflict, the spec is
# the authroity.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/authroity/authority/

@avade
Copy link
Contributor

avade commented Jan 11, 2018

I propose that this is now merged and further refinements are new PRs

LGTM

Approved with PullApprove

@angarg12
Copy link
Contributor

Would it make sense to put a link to the rendered swagger on the repo README so that it is easily accessible by people?

@angarg12
Copy link
Contributor

angarg12 commented Jan 11, 2018

LGTM

Approved with PullApprove

@n3wscott
Copy link
Contributor Author

Would it make sense to put a link to the rendered swagger on the repo README so that it is easily accessible by people?

Sounds like a good follow-up. Maybe even a symlink to a git tag when next release happens.

paths:
/v2/catalog:
get:
summary: get the catalog of services that the service broker offers
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we start these with capital letters? Get the catalog...
It looks better to me when generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can in a follow-up!

@duglin
Copy link
Contributor

duglin commented Jan 12, 2018

I'm new to OAPI but is there a way in the "Example Value" that it generates to have it do something like add a "?" when a field is optional? Showing that example is really helpful, but I'm missing the required/optional aspect of each field.

@duglin
Copy link
Contributor

duglin commented Jan 12, 2018

@maximilien ^^

@n3wscott
Copy link
Contributor Author

n3wscott commented Jan 12, 2018

is there a way in the "Example Value" that it generates to have it do something like add a "?" when a field is optional

@duglin This is a quirk of the default swagger ui, click the tab next to "example value" called "Model" and you will see the object in table format with the required fields with descriptions if the model has them.

@duglin
Copy link
Contributor

duglin commented Jan 12, 2018

Ah, I didn't realize the "Model" thing was a link - nice

@vaikas
Copy link
Contributor

vaikas commented Jan 12, 2018

LGTM

Approved with PullApprove

@duglin
Copy link
Contributor

duglin commented Jan 13, 2018

@n3wscott did you want to fix the two spots @mattmcneeney commented on?

@n3wscott
Copy link
Contributor Author

did you want to fix the two spots @mattmcneeney commented on?

@duglin the error pr is not in yet I think

@duglin
Copy link
Contributor

duglin commented Jan 16, 2018

Sorry, not sure what you mean by "error pr"

@duglin
Copy link
Contributor

duglin commented Jan 16, 2018

Matt are your issues resolved? github shows you're still requesting changes

@mattmcneeney
Copy link
Contributor

Yes - but if we can get #409 merged then it'd be awesome to update the OpenAPI doc with that change before merging it in (as it makes many of the errors much simpler)

@duglin
Copy link
Contributor

duglin commented Jan 16, 2018

@n3wscott I think there are a few edits that people want to see before we merge this - any chance of getting those in?

@mattmcneeney
Copy link
Contributor

mattmcneeney commented Jan 16, 2018

LGTM

Approved with PullApprove

@angarg12 angarg12 merged commit 7f22373 into openservicebrokerapi:master Jan 16, 2018
@n3wscott n3wscott deleted the openapi branch April 2, 2018 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants