Skip to content

Commit

Permalink
Added support for non-200 response code (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
akhromets authored May 8, 2024
1 parent 8973f56 commit 36a27ef
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.idea

# code coverage
/coverage
Expand Down
15 changes: 15 additions & 0 deletions .snapshot/all/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ export class CategoryService extends BaseHttpService {
}
}

@Injectable({
providedIn: 'root'
})
export class FeedbackService extends BaseHttpService {
constructor(http: HttpClient) {
super(getBasePath('', '/api/feedback'), http);
}

public postFeedback(): Observable<void> {
return this.post<void>(
``,
);
}
}

@Injectable({
providedIn: 'root'
})
Expand Down
16 changes: 16 additions & 0 deletions .snapshot/withRequestOptions/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ export class CategoryService extends BaseHttpService {
}
}

@Injectable({
providedIn: 'root'
})
export class FeedbackService extends BaseHttpService {
constructor(http: HttpClient) {
super(getBasePath('', '/api/feedback'), http);
}

public postFeedback(options?: $types.TypeOrUndefined<IAngularHttpRequestOptions>): Observable<void> {
return this.post<void>(
``,
options,
);
}
}

@Injectable({
providedIn: 'root'
})
Expand Down
22 changes: 22 additions & 0 deletions __tests__/swagger/OpenAPIService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ describe('OpenAPIService tests', () => {
expect(service.getSchemasByEndpoints(new Set<string>())).toEqual({});
});

test('response with not 200 code', () => {
const spec: IOpenAPI3 = {
...defaultSpec,
openapi: '3.0.1',
paths: {
'/product/test': {
post: {
responses: {
201: {
description: 'Created'
}
}
}
}
}
};

const service = new OpenAPIService(spec, guard);
const endpoints = service.getEndpoints();
expect(service.getSchemasByEndpoints(new Set<string>(endpoints))).toEqual({});
});

test('recursion', () => {
const spec: IOpenAPI3 = {
openapi: '3.0.1',
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luxbss/gengen",
"version": "1.2.6",
"version": "1.2.7",
"description": "Tool for generating models and Angular services based on OpenAPIs and Swagger's JSON",
"bin": {
"gengen": "./bin/index.js"
Expand Down
4 changes: 2 additions & 2 deletions src/services/ServiceMappingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class ServiceMappingService {
name: lowerFirst(actionName),
operation: method,
parameters: this.getUriParameters(operation.parameters),
returnType: this.getTypeInfo(operation.responses[200].content?.['application/json']?.schema, modelFinder),
returnType: this.getTypeInfo(operation.responses[200]?.content?.['application/json']?.schema, modelFinder),
originUri
};

Expand Down Expand Up @@ -224,6 +224,6 @@ export class ServiceMappingService {
}

private hasDownloadResponse(operation: IOpenAPI3Operation): boolean {
return Boolean(operation.responses[200].content?.['application/octet-stream']);
return Boolean(operation.responses[200]?.content?.['application/octet-stream']);
}
}
2 changes: 1 addition & 1 deletion src/swagger/OpenAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class OpenAPIService {
return [
...refs,
...this.getRefsFromSchema(operation.requestBody?.content['application/json']?.schema),
...this.getRefsFromSchema(operation.responses[200].content?.['application/json']?.schema)
...this.getRefsFromSchema(operation.responses[200]?.content?.['application/json']?.schema)
];
}

Expand Down
5 changes: 4 additions & 1 deletion src/swagger/v3/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IOpenAPI3Operation {
tags?: string[];
parameters?: IOpenAPI3Parameter[];
responses: {
200: {
200?: {
description?: 'Success';
content?: {
'application/json'?: {
Expand All @@ -20,6 +20,9 @@ export interface IOpenAPI3Operation {
};
};
};
201?: {
description?: 'Created';
};
};
requestBody?: {
content: {
Expand Down
20 changes: 19 additions & 1 deletion swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,24 @@
}
}
}
},
"/api/feedback": {
"post": {
"tags": [
"feedback"
],
"responses": {
"201": {
"description": "Created"
},
"400": {
"description": "Bad Request"
},
"500": {
"description": "Server Error"
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -724,4 +742,4 @@
}
}
}
}
}

0 comments on commit 36a27ef

Please sign in to comment.