@@ -50,7 +50,8 @@ import {
50
50
modelTypeAlias ,
51
51
parseVariantNameTag ,
52
52
parseVariantsTag ,
53
- verifyUniqueness
53
+ verifyUniqueness ,
54
+ parseJsDocTags
54
55
} from './utils'
55
56
56
57
const specsFolder = join ( __dirname , '..' , '..' , 'specification' )
@@ -214,6 +215,14 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
214
215
)
215
216
) ]
216
217
218
+ const pathAndQueryProperties = ( declaration . getMembers ( ) as any [ ] ) . flatMap ( member => {
219
+ const property = visitRequestOrResponseProperty ( member )
220
+ if ( property . name === 'path_parts' || property . name === 'query_parameters' ) {
221
+ return property . properties . map ( property => property . name )
222
+ } else if ( property . name === 'body' ) {
223
+ return undefined
224
+ }
225
+ } )
217
226
for ( const member of declaration . getMembers ( ) ) {
218
227
// we are visiting `path_parts, `query_parameters` or `body`
219
228
assert (
@@ -242,6 +251,22 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
242
251
type . body = { kind : 'no_body' }
243
252
} else {
244
253
type . body = { kind : 'value' , value : property . valueOf }
254
+ const openGenerics = declaration . getTypeParameters ( ) . map ( modelGenerics )
255
+ if ( ( property . valueOf . kind === 'instance_of' && openGenerics . includes ( property . valueOf . type . name ) ) ||
256
+ property . valueOf . kind === 'array_of' ) {
257
+ const tags = parseJsDocTags ( member . getJsDocs ( ) )
258
+ assert (
259
+ member ,
260
+ tags . identifier != null ,
261
+ 'You should configure a body @identifier'
262
+ )
263
+ assert (
264
+ member . getJsDocs ( ) ,
265
+ ! pathAndQueryProperties . includes ( tags . identifier ) ,
266
+ `The identifier '${ tags . identifier } ' already exists as a property in the path or query.`
267
+ )
268
+ type . body . identifier = tags . identifier
269
+ }
245
270
}
246
271
} else if ( property . properties . length > 0 ) {
247
272
type . body = { kind : 'properties' , properties : property . properties }
0 commit comments