File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change
1
+ import type * as Types from "./types" ;
2
+
3
+ export const generateValidRootSchema = ( input : Types . OpenApi . Document ) : Types . OpenApi . Document => {
4
+ if ( ! input . paths ) {
5
+ return input ;
6
+ }
7
+ /** update undefined operation id */
8
+ for ( const [ path , methods ] of Object . entries ( input . paths || { } ) ) {
9
+ for ( const [ method , operation ] of Object . entries ( methods || { } ) ) {
10
+ if ( ! operation . operationId ) {
11
+ operation . operationId = `${ method . toLowerCase ( ) } ${ path . charAt ( 0 ) . toUpperCase ( ) + path . slice ( 1 ) } ` ;
12
+ }
13
+ }
14
+ }
15
+ return input ;
16
+ } ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { EOL } from "os";
2
2
3
3
import * as Api from "./api" ;
4
4
import type * as Types from "./types" ;
5
+ import { generateValidRootSchema } from "./generateValidRootSchema" ;
5
6
6
7
export interface Option {
7
8
allowOperationIds ?: string [ ] ;
@@ -17,7 +18,7 @@ export class CodeGenerator {
17
18
private option ?: Option ,
18
19
) {
19
20
if ( typeof entryPointOrDocument === "string" ) {
20
- this . rootSchema = Api . FileSystem . loadJsonOrYaml ( entryPointOrDocument ) ;
21
+ this . rootSchema = generateValidRootSchema ( Api . FileSystem . loadJsonOrYaml ( entryPointOrDocument ) ) ;
21
22
this . resolvedReferenceDocument = Api . ResolveReference . resolve (
22
23
entryPointOrDocument ,
23
24
entryPointOrDocument ,
You can’t perform that action at this time.
0 commit comments