@@ -7,11 +7,14 @@ import { serialize } from '@azure-tools/codegen';
77import { PwshModel } from '../utils/PwshModel' ;
88import { NewModelState } from '../utils/model-state' ;
99import { StatusCodes } from '../utils/http-definitions' ;
10+ import { items , values , keys , Dictionary , length } from '@azure-tools/linq' ;
1011
1112import { Host } from '@azure-tools/autorest-extension-base' ;
1213
1314type State = NewModelState < PwshModel > ;
1415
16+ let directives : Array < any > = [ ] ;
17+
1518async 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+ }
2743function 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
155171export 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