@@ -62,7 +62,11 @@ public void applyResolutions(List<AuthorizationValue> auths) {
6262 Object mapping = ctx .object ;
6363 Object target = ctx .parent ;
6464 try {
65- String contents = new RemoteUrl ().urlToString (host , auths );
65+ String contents = null ;
66+ if (host .startsWith ("http" ))
67+ contents = new RemoteUrl ().urlToString (host , auths );
68+ else
69+ contents = Json .mapper ().writeValueAsString (swagger );
6670 JsonNode location = null ;
6771 String locationName = null ;
6872 if (contents != null ) {
@@ -94,6 +98,24 @@ else if(target instanceof Parameter) {
9498 swagger .addDefinition (locationName , model );
9599 }
96100 }
101+ else if (target instanceof Operation ) {
102+
103+ // get the operation position
104+ Operation operation = (Operation ) target ;
105+ int position = 0 ;
106+ for (Parameter param : operation .getParameters ()) {
107+
108+ if (param instanceof RefParameter ) {
109+ RefParameter ref = (RefParameter ) param ;
110+ if (ref .getSimpleRef ().equals (locationName )) {
111+ // found a match!
112+ Parameter remoteParam = Json .mapper ().convertValue (location , Parameter .class );
113+ operation .getParameters ().set (position , remoteParam );
114+ }
115+ }
116+ position += 1 ;
117+ }
118+ }
97119 }
98120 }
99121 catch (Exception e ) {
@@ -102,7 +124,6 @@ else if(target instanceof Parameter) {
102124 }
103125 }
104126 }
105- // Json.prettyPrint(resolutionMap);
106127 }
107128
108129 public void detectOperationRefs () {
@@ -113,14 +134,35 @@ public void detectOperationRefs() {
113134 Path path = paths .get (pathName );
114135 List <Operation > operations = path .getOperations ();
115136 for (Operation operation : operations ) {
116- for (Parameter parameter : operation .getParameters ()) {
117- if (parameter instanceof BodyParameter ) {
118- BodyParameter bp = (BodyParameter ) parameter ;
119- if (bp .getSchema () != null && bp .getSchema () instanceof RefModel ) {
120- RefModel ref = (RefModel )bp .getSchema ();
121- if (ref .get$ref ().startsWith ("http" )) {
122- LOGGER .debug ("added reference to " + ref .get$ref ());
123- resolutionMap .put (ref .get$ref (), new ResolutionContext (ref , bp , "ref" ));
137+ if (operation .getParameters () != null ) {
138+ for (Parameter parameter : operation .getParameters ()) {
139+ if (parameter instanceof BodyParameter ) {
140+ BodyParameter bp = (BodyParameter ) parameter ;
141+ if (bp .getSchema () != null && bp .getSchema () instanceof RefModel ) {
142+ RefModel ref = (RefModel )bp .getSchema ();
143+ if (ref .get$ref ().startsWith ("http" )) {
144+ LOGGER .debug ("added reference to " + ref .get$ref ());
145+ resolutionMap .put (ref .get$ref (), new ResolutionContext (ref , bp , "ref" ));
146+ }
147+ }
148+ }
149+ else if (parameter instanceof RefParameter ) {
150+ RefParameter ref = (RefParameter ) parameter ;
151+ LOGGER .debug ("added reference to " + ref .get$ref ());
152+ resolutionMap .put (ref .get$ref (), new ResolutionContext (ref , operation , "inline" ));
153+ }
154+ }
155+ }
156+ if (operation .getResponses () != null ) {
157+ for (String responseCode : operation .getResponses ().keySet ()) {
158+ Response response = operation .getResponses ().get (responseCode );
159+ if (response .getSchema () != null ) {
160+ Property schema = response .getSchema ();
161+ if (schema instanceof RefProperty ) {
162+ RefProperty ref = (RefProperty ) schema ;
163+ if (ref .get$ref () != null && ref .get$ref ().startsWith ("http" )) {
164+ resolutionMap .put (ref .get$ref (), new ResolutionContext (ref , response , "ref" ));
165+ }
124166 }
125167 }
126168 }
0 commit comments