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 treat default type as error #1654

Closed
wants to merge 3 commits into from

Conversation

csteegz
Copy link

@csteegz csteegz commented Dec 5, 2016

Addresses #1523

This takes the opinion that there is one canonical error response, which is defined in the swagger as the default response. To reflect that, all responses that share the error response's model are treated as the default case, and ignored.

@azuresdkci
Copy link

Can one of the admins verify this patch?

@azurecla
Copy link

azurecla commented Dec 5, 2016

Hi @csteegz, I'm your friendly neighborhood Azure Pull Request Bot (You can call me AZPRBOT). Thanks for your contribution!


It looks like you're working at Microsoft (coverste). If you're full-time, we DON'T require a contribution license agreement.



If you are a vendor, DO please sign the electronic contribution license agreement. It will take 2 minutes and there's no faxing! https://cla.azure.com.

TTYL, AZPRBOT;

Copy link
Member

@fearthecowboy fearthecowboy left a comment

Choose a reason for hiding this comment

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

We need to make sure that this is covering all the scenarios

@@ -51,14 +50,13 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName,
{
EnsureUniqueMethodName(methodName, methodGroup);

var method = New<Method>(new
{
var method = New<Method>(new {
Copy link
Member

Choose a reason for hiding this comment

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

While personally, I'd prefer using the 1TBS, the rest of the project uses the traditional ANSI-style braces, and I'd prefer to keep code changes in a single brace format.

If you could tweak the braces to be consistent that'd be great.

@@ -96,16 +94,12 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName,

var headerTypeName = string.Format(CultureInfo.InvariantCulture,
"{0}-{1}-Headers", methodGroup, methodName).Trim('-');
var headerType = New<CompositeType>(headerTypeName,new
{
var headerType = New<CompositeType>(headerTypeName, new {
Copy link
Member

Choose a reason for hiding this comment

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

Switch to ANSI-style Braces


var property = New<Property>(new
{
responseHeaders.ForEach(h => {
Copy link
Member

Choose a reason for hiding this comment

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

Switch to ANSI-style Braces

@@ -142,8 +136,7 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName,
private static IEnumerable<SwaggerParameter> DeduplicateParameters(IEnumerable<SwaggerParameter> parameters)
{
return parameters
.Select(s =>
{
.Select(s => {
Copy link
Member

Choose a reason for hiding this comment

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

Switch to ANSI-style Braces

@@ -241,8 +261,7 @@ private Response BuildMethodReturnType(List<Stack<IModelType>> types, IModelType
}

// BuildParameter up type inheritance tree
types.ForEach(typeStack =>
{
types.ForEach(typeStack => {
Copy link
Member

Choose a reason for hiding this comment

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

ANSI Braces Please.

if (errorModelType == null || method.Responses == null) return;
var keys = method.Responses.Keys;
var removeResponses = new List<HttpStatusCode>();
foreach (var key in keys)
Copy link
Member

Choose a reason for hiding this comment

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

The response types for error conditions should be related (ie, default uses #/definitions/SomeError and all the other error responses should use something that either returns that type, or has an allOf: "#/definitions/SomeError" in it's type declaration.)

That way we can have very specific types for errors, and makes it very clear what's an acceptable error.

Of course that means we have to do three other things:

  • make sure that use of the allOf doesn't force type-inheritance, it's possible that we should be able to have two error types that bubble up to the same swagger model type (that doesn't even have any properties), but still generate individual classes without a hierarchy.

  • change the generator to throw the correct exception type, rather than living with the default class

  • and add method documentation for known possible exceptions

@olydis
Copy link
Contributor

olydis commented Sep 11, 2017

closing due to inactivity (there are issues tracking and referring to this PR)

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.

5 participants