@@ -988,6 +988,60 @@ func generateErrorsFile(s spec.Swagger) (string, error) {
988988 }
989989 }
990990
991+ subrouters , err := swagger .ParseSubrouters (s )
992+ if err != nil {
993+ return "" , err
994+ }
995+
996+ for _ , router := range subrouters {
997+ subspec , err := swagger .LoadSubrouterSpec (router )
998+ if err != nil {
999+ return "" , err
1000+ }
1001+
1002+ for _ , pathKey := range swagger .SortedPathItemKeys (subspec .Paths .Paths ) {
1003+ path := subspec .Paths .Paths [pathKey ]
1004+ pathItemOps := swagger .PathItemOperations (path )
1005+ for _ , opKey := range swagger .SortedOperationsKeys (pathItemOps ) {
1006+ op := pathItemOps [opKey ]
1007+ for _ , statusCode := range swagger .SortedStatusCodeKeys (op .Responses .StatusCodeResponses ) {
1008+ if statusCode < 400 {
1009+ continue
1010+ }
1011+ typeName , _ := swagger .OutputType (& s , op , statusCode )
1012+ if strings .HasPrefix (typeName , "models." ) {
1013+ typeName = typeName [7 :]
1014+ }
1015+ if typeNames .Contains (typeName ) {
1016+ log .Printf (
1017+ "Duplicate type name %s declared in %s subrouter spec\n " ,
1018+ typeName ,
1019+ router .Key ,
1020+ )
1021+ continue
1022+ }
1023+ typeNames .Add (typeName )
1024+
1025+ etype := errorType {
1026+ StatusCode : statusCode ,
1027+ Name : typeName ,
1028+ }
1029+
1030+ if schema , ok := subspec .Definitions [typeName ]; ! ok {
1031+ log .Printf ("TODO: could not find schema for %s, JS documentation will be incomplete" , typeName )
1032+ } else if len (schema .Properties ) > 0 {
1033+ for _ , name := range swagger .SortedSchemaProperties (schema ) {
1034+ propertySchema := schema .Properties [name ]
1035+ etype .JSDocProperties = append (etype .JSDocProperties , jsDocPropertyFromSchema (name , & propertySchema ))
1036+ }
1037+ }
1038+
1039+ typesTmpl .ErrorTypes = append (typesTmpl .ErrorTypes , etype )
1040+ }
1041+ }
1042+ }
1043+ }
1044+
9911045 return templates .WriteTemplate (typeTmplString , typesTmpl )
9921046}
9931047
0 commit comments