forked from ryankennedy/swagger-jaxrs-doclet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge methods of root resources. fixes ryankennedy#74
- Loading branch information
1 parent
ea650c1
commit 37d0761
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
jaxrs-doclet/src/main/java/com/hypnoticocelot/jaxrs/doclet/parser/ParserHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.hypnoticocelot.jaxrs.doclet.parser; | ||
|
||
import com.hypnoticocelot.jaxrs.doclet.model.Api; | ||
import com.hypnoticocelot.jaxrs.doclet.model.ApiDeclaration; | ||
import com.hypnoticocelot.jaxrs.doclet.model.Model; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ParserHelper { | ||
|
||
public static Api findApiWithSamePath(Collection<Api> apis, Api api) { | ||
for (Api a : apis) { | ||
if (a.getPath().equals(api.getPath())) { | ||
return a; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static void mergeApis(Collection<Api> apis, Collection<Api> apis1) { | ||
for (Api api : apis1) { | ||
Api samePathApi = findApiWithSamePath(apis, api); | ||
if (samePathApi == null) { | ||
apis.add(api); | ||
} else { | ||
samePathApi.getOperations().addAll(api.getOperations()); | ||
} | ||
} | ||
} | ||
|
||
public static ApiDeclaration findDeclarationWithSamePath(Collection<ApiDeclaration> declarations, | ||
ApiDeclaration declaration) { | ||
for (ApiDeclaration d : declarations) { | ||
if (d.getResourcePath().equals(declaration.getResourcePath())) { | ||
return d; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static void mergeDeclarations(Collection<ApiDeclaration> declarations, ApiDeclaration declaration) { | ||
ApiDeclaration samePathDeclaration = findDeclarationWithSamePath(declarations, declaration); | ||
if (samePathDeclaration == null) { | ||
declarations.add(declaration); | ||
return; | ||
} | ||
|
||
declarations.remove(samePathDeclaration); | ||
mergeApis(samePathDeclaration.getApis(), declaration.getApis()); | ||
Map<String, Model> models = new HashMap<>(samePathDeclaration.getModels()); | ||
models.putAll(declaration.getModels()); | ||
declarations.add(new ApiDeclaration(declaration.getApiVersion(), | ||
declaration.getBasePath(), declaration.getResourcePath(), samePathDeclaration.getApis(), models)); | ||
} | ||
} |