Skip to content

Commit ee9a568

Browse files
authored
Add support for no-inline (#691)
1 parent c923769 commit ee9a568

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

powershell/plugins/plugin-create-inline-properties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function createVirtualProperties(schema: ObjectSchema, stack: Array<string>, thr
160160
// dolauli pay attention to the condition check
161161
const isDict = property.schema.type === SchemaType.Dictionary || (<ObjectSchema>property.schema).parents?.immediate?.find((s) => s.type === SchemaType.Dictionary);
162162
const canInline =
163-
// (!property.schema.details.default['skip-inline']) &&
163+
(!property.schema.language.default['skip-inline']) &&
164164
(!<ObjectSchema>property.schema.language.default.byReference) &&
165165
(!isDict) &&
166166
(<ObjectSchema>property.schema).language.default.inline === 'yes';

powershell/plugins/plugin-tweak-m4-model.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import { serialize } from '@azure-tools/codegen';
77
import { PwshModel } from '../utils/PwshModel';
88
import { NewModelState } from '../utils/model-state';
99
import { StatusCodes } from '../utils/http-definitions';
10+
import { items, values, keys, Dictionary, length } from '@azure-tools/linq';
1011

1112
import { Host } from '@azure-tools/autorest-extension-base';
1213

1314
type State = NewModelState<PwshModel>;
1415

16+
let directives: Array<any> = [];
17+
1518
async function tweakModel(state: State): Promise<PwshModel> {
1619
const model = state.model;
1720

@@ -21,9 +24,22 @@ async function tweakModel(state: State): Promise<PwshModel> {
2124

2225
removeM4DefaultDescription(model);
2326

27+
handleNoinlineDirective(state);
28+
2429
return model;
2530
}
2631

32+
function handleNoinlineDirective(state: State) {
33+
var inlineModels: string[] = new Array;
34+
for (const directive of directives.filter(each => each['no-inline'])) {
35+
inlineModels = inlineModels.concat(<ConcatArray<string>>values(directive['no-inline']).toArray());
36+
}
37+
for (const model of state.model.schemas.objects || []) {
38+
if (inlineModels.includes(model.language.default.name)) {
39+
model.language.default['skip-inline'] = true;
40+
}
41+
}
42+
}
2743
function addResponseHeaderSchema(model: CodeModel) {
2844
// In remodeler, each operations response headers will has its own scheam. Each header will be schema's property.
2945
// But in m4, if 'schema' is not explicitly defined, even 'headers' is specified, there won't be a schema for headers.
@@ -153,6 +169,8 @@ function recursiveRemoveM4DefaultDescription(schema: Schema, visited: Set<Schema
153169
}
154170

155171
export async function tweakM4ModelPlugin(service: Host) {
172+
const allDirectives = await service.GetValue('directive');
173+
directives = values(allDirectives).toArray();
156174
const state = await new NewModelState<PwshModel>(service).init();
157175
service.WriteFile('code-model-v4-tweakm4codemodel.yaml', serialize(await tweakModel(state)), undefined, 'code-model-v4');
158176
}

0 commit comments

Comments
 (0)