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 option to model implicit default response #229

Merged
merged 3 commits into from
Mar 15, 2018

Conversation

vladbarosan
Copy link

Fixes #224
Fixes #228

@vladbarosan
Copy link
Author

Will update with new reference to Sway after https://github.com/amarzavery/sway/pull/25 gets merged.

Copy link
Contributor

@amarzavery amarzavery left a comment

Choose a reason for hiding this comment

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

Can we add a test for this to ensure that we are doing the right thing with default?

*/
exports.CloudError = {
description: "Error response describing why the operation failed.",
schema: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you are trying to do. However if possible do not nest properties. That will make sure that when we use oneOf for nullable types we do not do anything drastic.

Copy link
Author

Choose a reason for hiding this comment

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

not sure what you mean. Also here would prefer to not have nullable types since there is no reason for that.


// going through responses
if (operation.responses && !operation.responses.default) {
operation.responses.default = utils.CloudError;
Copy link
Contributor

@amarzavery amarzavery Mar 15, 2018

Choose a reason for hiding this comment

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

operation.responses.default = utils.CloudErrorSchema;
if (!spec.definitions.CloudError) {
  spec.definitions.CloudErrorWrapper = utils.CloudErrorWrapper;
  spec.definitions.CloudError = utils.CloudError;
}

Copy link
Author

Choose a reason for hiding this comment

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

@amarzavery so you prefer to define the cloud error in the definitions and then just make a ref to it ? that works I think

/**
* Models an ARM cloud error.
*/
exports.CloudError = {
Copy link
Contributor

@amarzavery amarzavery Mar 15, 2018

Choose a reason for hiding this comment

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

exports.CloudErrorSchema = {
  description: "Error response describing why the operation failed.",
  schema: {
     "$ref": "#/definitions/CloudErrorWrapper"
   }
};

exports.CloudErrorWrapper = {
  "type": "object",
  properties: {
      error: {
         "$ref": "#/definitions/CloudError"
      }
   },
  additionalProperties: false
};

exports.CloudError = {
  "type": "object",
  properties: {
     code: {
        type: "string",
        description: "An identifier for the error. Codes are invariant and are intended to be consumed programmatically."
     },
      message: {
            type: "string",
            description: "A message describing the error, intended to be suitable for display in a user interface."
       },
       target: {
            type: "string",
            description: "The target of the particular error. For example, the name of the property in error."
       },
       details: {
            type: "array",
            items: { type: "object" },
            description: "A list of additional details about the error."
       },
       additionalInfo: {
            type: "array",
            items: { type: "object" },
            description: "A list of additional info about an error."
       }
    },
     additionalProperties: false
  };

Copy link
Contributor

Choose a reason for hiding this comment

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

This should keep things in sync with our current design. Do not forget "type": "object" in the model definitions for CloudErrorWrapper and CloudError. Now you know the consequences of missing "type" on a model definitions. Couple of questions:

  1. CloudErrorWrapper has only one property "error". Shouldn't that be a required property?
  2. Are there any required properties in "CloudError" model? I think at minimum there should be code and message. Otherwise what is the point of the error object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

thanks for the link, I was looking in the specs repo and those were not marked as required. Btw should we live the innerError and add the new additionalInfo ? (If you saw the email from Gaurav)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I saw that email. I think we should have CloudErrorV1 and CloudErrorV2. Looks like some teams will be providing innerErrors for the already deployed api-versions. We can make our CloudError object a oneOf [V1, V2]. If we do that then we should make sure to not add CloudError during semantic validation, since oneOf is not supported in 2.0 version of the swagger spec.

Copy link
Author

Choose a reason for hiding this comment

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

well are we sure those are required ?either way this change is not intended to catch invalid cloud errors, is mostly to avoid noise from those and potentially catch any other non-described errors. So maybe I would just leave both innerError and additionalInfo. We can refine in the future

items: { type: "object" },
description: "A list of additional details about the error."
},
additionalInfo: {
Copy link
Contributor

Choose a reason for hiding this comment

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

wanna add innerError as well?

Copy link
Author

Choose a reason for hiding this comment

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

yes just that the spec is a little confusing. It says the type is string but it seems to be an object. I'll just leave it without specifying any type.

Copy link
Author

Choose a reason for hiding this comment

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

ah nevermind, it seems to be always an object

Copy link
Author

Choose a reason for hiding this comment

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

done

@amarzavery amarzavery merged commit b83f50a into Azure:master Mar 15, 2018
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.

2 participants