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";
22
33import * as Api from "./api" ;
44import type * as Types from "./types" ;
5+ import { generateValidRootSchema } from "./generateValidRootSchema" ;
56
67export interface Option {
78 allowOperationIds ?: string [ ] ;
@@ -17,7 +18,7 @@ export class CodeGenerator {
1718 private option ?: Option ,
1819 ) {
1920 if ( typeof entryPointOrDocument === "string" ) {
20- this . rootSchema = Api . FileSystem . loadJsonOrYaml ( entryPointOrDocument ) ;
21+ this . rootSchema = generateValidRootSchema ( Api . FileSystem . loadJsonOrYaml ( entryPointOrDocument ) ) ;
2122 this . resolvedReferenceDocument = Api . ResolveReference . resolve (
2223 entryPointOrDocument ,
2324 entryPointOrDocument ,
You can’t perform that action at this time.
0 commit comments