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 support for default response and fix an issue related to model #635

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion powershell/cmdlets/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ export class NewCmdletClass extends Class {
}

// create the response handlers
const responses = [...values(apiCall.responses)];
const responses = [...values(apiCall.responses), ...values(apiCall.exceptions)];

const callbackMethods = values(responses).toArray().map(each => new LiteralExpression(each.language.csharp?.name || ''));

Expand Down
4 changes: 2 additions & 2 deletions powershell/llcsharp/operation/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class NewOperationMethod extends Method {
// this.addParameter(this.bodyParameter);
// }

for (const response of values(this.operation.responses)) {
for (const response of [...values(this.operation.responses), ...values(this.operation.exceptions)]) {

const responseType = (<SchemaResponse>response).schema ? state.project.modelsNamespace.NewResolveTypeDeclaration(<NewSchema>((<SchemaResponse>response).schema), true, state) : null;
//skip-for-time-being
Expand Down Expand Up @@ -887,7 +887,7 @@ export class NewCallMethod extends Method {

// add response handlers
yield Switch(`${response}.StatusCode`, function* () {
for (const responses of values(opMethod.operation.responses)) {
for (const responses of [...values(opMethod.operation.responses), ...values(opMethod.operation.exceptions)]) {
if (responses.protocol.http?.statusCodes[0] !== 'default') {
const responseCode = responses.protocol.http?.statusCodes[0];
// will use enum when it can, fall back to casting int when it can't
Expand Down
15 changes: 9 additions & 6 deletions powershell/plugins/cs-namer-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ function setSchemaNames(schemaGroups: Dictionary<Array<Schema>>, azure: boolean,

// create the namespace if required
if (azure) {
const metadata = schema.extensions && schema.extensions['x-ms-metadata'];
if (metadata) {
const apiVersions = <Array<string> | undefined>metadata.apiVersions;
if (apiVersions && length(apiVersions) > 0) {
thisApiversion = minimum(apiVersions);
const versions = [...values(schema.apiVersions).select(v => v.version)];
if (schema.language.default?.uid !== 'universal-parameter-type') {
if (versions && length(versions) > 0) {
thisApiversion = minimum(versions);
thisNamespace = subNamespace.get(thisApiversion) || new Set<string>();
subNamespace.set(thisApiversion, thisNamespace);
}
}
}


// for each schema, we're going to set the name
// to the suggested name, unless we have collisions
// at which point, we're going to add a number (for now?)
Expand Down Expand Up @@ -195,7 +195,9 @@ async function setOperationNames(state: State, resolver: NewSchemaDefinitionReso
};
}

for (const rsp of values(operation.responses)) {
const responses = [...values(operation.responses), ...values(operation.exceptions)];

for (const rsp of responses) {
// per responseCode
const response = <SchemaResponse>rsp;
const responseTypeDefinition = response.schema ? resolver.resolveTypeDeclaration(<any>response.schema, true, state) : undefined;
Expand All @@ -205,6 +207,7 @@ async function setOperationNames(state: State, resolver: NewSchemaDefinitionReso
if (response.protocol.http?.statusCodes[0] === 'default' || rawValue === 'default' || '') {
rawValue = 'any response code not handled elsewhere';
code = 'default';
response.language.default.isErrorResponse = true;
}
response.language.csharp = {
...response.language.default,
Expand Down