1616
1717package com.github.hauner.openapi.spring.converter
1818
19+ import com.github.hauner.openapi.spring.converter.mapping.AmbiguousTypeMappingException
20+ import com.github.hauner.openapi.spring.converter.mapping.EndpointTypeMapping
21+ import com.github.hauner.openapi.spring.converter.mapping.Mapping
22+ import com.github.hauner.openapi.spring.converter.mapping.MappingSchema
1923import com.github.hauner.openapi.spring.model.Interface
2024import io.swagger.v3.oas.models.Operation
2125import io.swagger.v3.oas.models.PathItem
@@ -32,6 +36,25 @@ class InterfaceCollector {
3236
3337 private ApiOptions options
3438
39+ class MappingSchemaEndpoint implements MappingSchema {
40+ String path
41+
42+ @Override
43+ String getPath () {
44+ path
45+ }
46+
47+ @Override
48+ String getName () {
49+ null
50+ }
51+
52+ @Override
53+ String getContentType () {
54+ null
55+ }
56+ }
57+
3558 InterfaceCollector (ApiOptions options ) {
3659 this . options = options
3760 }
@@ -49,7 +72,11 @@ class InterfaceCollector {
4972 paths. each { Map.Entry <String , PathItem > entry ->
5073 def operations = collectOperations (entry. value)
5174 operations. each { op ->
52- String targetInterfaceName = getInterfaceName (op)
75+ String targetInterfaceName = getInterfaceName (op, isExcluded (entry. key))
76+
77+ if (interfaces. containsKey (targetInterfaceName)) {
78+ return
79+ }
5380
5481 def itf = new Interface (
5582 pkg : [options. packageName, ' api' ]. join (' .' ),
@@ -63,17 +90,38 @@ class InterfaceCollector {
6390 interfaces. values () as List
6491 }
6592
93+ private boolean isExcluded (String path ) {
94+ def endpointMatches = options. typeMappings. findAll {
95+ it. matches (Mapping.Level . ENDPOINT , new MappingSchemaEndpoint (path : path))
96+ }
97+
98+ if (! endpointMatches. empty) {
99+ if (endpointMatches. size () != 1 ) {
100+ throw new AmbiguousTypeMappingException (endpointMatches)
101+ }
102+
103+ def match = endpointMatches. first () as EndpointTypeMapping
104+ return match. exclude
105+ }
106+
107+ false
108+ }
109+
66110 private List<Operation > collectOperations (PathItem item ) {
67111 new OperationCollector (). collect (item)
68112 }
69113
70- private String getInterfaceName (def op ) {
114+ private String getInterfaceName (def op , boolean excluded ) {
71115 String targetInterfaceName = INTERFACE_DEFAULT_NAME
72116
73117 if (hasTags (op)) {
74118 targetInterfaceName = op. tags. first ()
75119 }
76120
121+ if (excluded) {
122+ targetInterfaceName + = ' Excluded'
123+ }
124+
77125 targetInterfaceName
78126 }
79127
0 commit comments