Loading…
Loading…
Explains how the platform generates import previews for WSDLs, including REST route suggestions, example SOAP/JSON payloads, and complexity analysis.
The ContractExampleService is a backend component that processes the results of a WSDL import to generate a comprehensive preview for an API publisher. Its primary function is to analyze each operation within a parsed WSDL, suggest a corresponding REST API structure, generate sample request and response payloads, and assess the complexity of automatically transforming the SOAP operation into a RESTful one.
This service solves the problem of understanding a complex WSDL file in the context of a REST-to-SOAP gateway. Instead of requiring manual inspection of the WSDL, it produces a structured report that includes:
zeroTouchScore) and review state (reviewState) to guide the onboarding process.xsd:choice or xsd:any.The service is called after a WSDL file has been successfully imported and parsed into a WsdlImportResult object. It uses this object, along with heuristics and other services, to build the preview, which is then typically used to populate a user interface for API publishers to review and configure their new API.
The ContractExampleService generates a preview by orchestrating several analysis and generation steps. The main entry point is the buildImportPreview method.
flowchart TD
subgraph Input
A[WsdlImportResult]
B(WsdlImportComparisonRecord <br/>- optional)
end
subgraph "ContractExampleService.buildImportPreview"
C[Get Draft Suggestions]
D{For each WSDL Operation}
E[Infer REST Route]
F[Inspect Route for Parameters]
G[Build Operation Preview]
H[Aggregate Summary Statistics]
end
subgraph "Operation Preview Generation"
G --> G1[Analyze Schema Complexity]
G --> G2[Calculate 'zeroTouchScore']
G --> G3[Determine 'reviewState']
G --> G4[Generate Example Payloads <br/>- SOAP & JSON <br/>- Minimal & Rich]
G --> G5[Build Example REST URL]
end
subgraph Output
I[Final Import Preview]
end
A --> C
A --> D
B --> D
C --> E
D --> E
E --> F
F --> G
D -- operation data --> G
G --> H
H --> IbuildImportPreview is called with a WsdlImportResult and an optional WsdlImportComparisonRecord (for showing changes from a previous version).OnboardingDraftSuggestionService to get baseline suggestions for the service, such as a proposed serviceKey.WsdlOperationRecord found in the import result.WsdlRestRouteHeuristics.inferRoute is used to propose a REST method (e.g., POST) and path (e.g., /v1/myservice/get-user). This process tracks used routes to detect and resolve collisions.WsdlRestRouteHeuristics.inspectRoute to identify which fields from the request schema are good candidates to become REST path parameters, query parameters, or body fields.buildOperationPreview, which assembles a detailed report for the single operation. This involves:
choice, wildcard (xsd:any), polymorphic types (xsi:type), and attribute usage.zeroTouchScore from 100 down, penalizing for each complexity flag found. Based on this score, it assigns a reviewState: READY_FOR_ZERO_TOUCH (score >= 90), READY_WITH_REVIEW (score >= 70), or COMPLEX_REVIEW.reviewState) and combines them with import metadata and the list of individual operation previews into a single map structure, which is the final output.Example values are generated by the generateRequestSample and generateResponseSample methods, which recursively render the contract schema.
ExampleFlavor enum:
MINIMAL: Includes only required fields.RICH: Includes required and a selection of optional fields.sampleScalar method generates a value based on the field's XSD type and name.
nameHasToken) to generate realistic samples for fields named email, phone, url, etc. This matching is token-aware to prevent matching substrings within words.min/maxInclusive/Exclusive, totalDigits, and fractionDigits facets. It generates whole numbers for fields that appear to be integers by name (e.g., orderId) or schema (fractionDigits=0).ConstrainedStringSampler to generate values that conform to pattern, minLength, and maxLength facets.xsd:pattern, the service uses RegexExampleGenerator to create a matching example string. This is crucial for fields like numeric dates (YYYYMMDD) that are typed as integers but have a strict format.The ContractExampleService exposes several public methods for generating previews and examples.
public Map<String, Object> buildImportPreview(WsdlImportResult result, WsdlImportComparisonRecord comparison)
: The main entry point. Generates a full import preview for all operations in a WsdlImportResult. An optional WsdlImportComparisonRecord can be provided to include diff information.
public Map<String, Object> buildOperationPreview(WsdlOperationRecord operation, ...)
: Generates a detailed preview for a single WsdlOperationRecord. This is primarily called by buildImportPreview.
public Object generateRequestSample(Map<String, Object> contract, ExampleFlavor flavor)
: Generates a sample JSON request payload from a contract schema map. The flavor determines whether to include only required fields (MINIMAL) or optional fields as well (RICH).
public Object generateResponseSample(Map<String, Object> contract)
: Generates a RICH sample JSON response payload from a contract schema map.
public List<Map<String, Object>> describeRequestFields(Map<String, Object> contract, ExampleFlavor flavor)
: Flattens a request contract schema into a list of field descriptors, including path, type, constraints, and an example value.
The buildImportPreview method returns a Map<String, Object> with a detailed, nested structure.
| Key | Type | Description |
|---|---|---|
artifactId | String | The unique identifier for the imported artifact. |
sourceType | String | The type of the source, e.g., WSDL. |
sourceName | String | The name of the source file or URL. |
targetNamespace | String | The targetNamespace from the WSDL. |
checksumSha256 | String | The SHA-256 checksum of the imported source file. |
importedAt | String (Timestamp) | The timestamp when the import occurred. |
backendSuggestion | Object | System-generated suggestions for the backend configuration. |
draftSuggestion | DraftSuggestionRecord | System-generated suggestions for the API draft, such as serviceKey. |
summary | Object | An object containing aggregate statistics about the operations. See Summary Object. |
comparison | WsdlImportComparisonRecord | The comparison record if one was provided, showing changes from a previous import. |
operations | List<Object> | A list of preview objects, one for each WSDL operation. See Operation Preview Object. |
The summary object provides a high-level overview of the import analysis.
| Key | Type | Description |
|---|---|---|
operationCount | Integer | The total number of operations found in the WSDL. |
readyForZeroTouch | Integer | The number of operations with a reviewState of READY_FOR_ZERO_TOUCH. |
readyWithReview | Integer | The number of operations with a reviewState of READY_WITH_REVIEW. |
complexReview | Integer | The number of operations with a reviewState of COMPLEX_REVIEW. |
missingContracts | Integer | The number of operations missing a request or response contract schema. |
routeFallbacks | Integer | The number of operations where a fallback strategy was used for route naming. |
routeCollisions | Integer | The number of operations where a route name collision was detected and resolved. |
Each object in the operations list provides a detailed analysis of a single WSDL operation.
| Key | Type | Description |
|---|---|---|
operationName | String | The name of the SOAP operation. |
inputMessage | String | The name of the WSDL input message. |
outputMessage | String | The name of the WSDL output message. |
soapAction | String | The SOAPAction value for the operation. |
requestSchema | Object | The structured contract schema for the request. |
responseSchema | Object | The structured contract schema for the response. |
requestContractReady | Boolean | true if the request schema was successfully generated. |
responseContractReady | Boolean | true if the response schema was successfully generated. |
zeroTouchScore | Integer | A score from 0-100 indicating suitability for automatic onboarding. |
reviewState | String | The assessed review state: READY_FOR_ZERO_TOUCH, READY_WITH_REVIEW, or COMPLEX_REVIEW. |
complexityFlags | List<String> | A list of flags for detected XSD complexities (e.g., choice, wildcard, attribute). |
reviewNotes | List<String> | Human-readable notes explaining the complexity flags and other findings. |
recommendedNextAction | String | A suggested next step for the API publisher based on the reviewState. |
suggestedOperationKey | String | A normalized, unique key for the operation, used in REST path generation. |
suggestedRestMethod | String | The suggested HTTP method for the REST endpoint (e.g., POST). |
suggestedRestPath | String | The suggested URL path for the REST endpoint (e.g., /my-service/v1/getUser). |
suggestedRestExampleUrl | String | A full example URL including populated path and query parameters. |
suggestedRouteSource | String | The heuristic source for the route suggestion (e.g., operation-key-default). |
routeCollisionResolved | Boolean | true if a naming collision with another operation's route was detected and resolved. |
suggestedRouteNote | String | A note explaining any special circumstances about the route suggestion. |
inferredResourceGroup | String | A heuristically inferred grouping for the operation. |
pathParameterCandidates | List<Object> | A list of request fields identified as candidates for REST path parameters. |
queryParameterCandidates | List<Object> | A list of request fields identified as candidates for REST query parameters. |
bodyFieldCandidates | List<Object> | A list of request fields identified as candidates to be included in the REST request body. |
requestFieldConfig | List<Object> | A flattened list of all fields in the request, with their types, constraints, and example values. |
suggestedRestBodyPayload | Object | The suggested JSON body for the REST request. Empty for GET and DELETE methods. |
soapNamespace | String | The SOAP namespace to be used in SOAP envelope generation. |
requestSamplePayload | Object | A minimal JSON example of the SOAP body payload. |
requestRichPayload | Object | A rich JSON example of the SOAP body payload, including some optional fields. |
requestSampleSoapEnvelope | String | A full SOAP 1.1 envelope containing the minimal request payload. |
requestRichSoapEnvelope | String | A full SOAP 1.1 envelope containing the rich request payload. |
responseSamplePayload | Object | A rich JSON example of the SOAP body payload for a successful response. |
responseSampleSoapEnvelope | String | A full SOAP 1.1 envelope containing the sample response payload. |
responseRoundTripPayload | Object | The JSON payload extracted by parsing the responseSampleSoapEnvelope, used to verify mapping logic. |
changeType | String | If a comparison was performed, indicates the type of change (e.g., MODIFIED, ADDED). |
breakingChange | Boolean | If a comparison was performed, indicates if the change is considered breaking. |
changeNotes | List<String> | If a comparison was performed, provides notes on what changed. |
While the service is designed to be robust, the complexity of WSDL and XSD schemas can lead to issues in the generated preview.
xsd:int) receives a string example (e.g., a URL) because its name contains a keyword like "uri". The current implementation avoids this by checking the field's type before applying name-based heuristics.totalDigits constraint. The generator now attempts to clamp the value to fit within the specified number of significant digits.pattern constraint (e.g., an xsd:int field requiring YYYYMMDD format). The generator now prioritizes creating an example from the pattern.pattern that is intended as a character allow-list with a maxLength. The pattern validator has a fallback to treat such patterns as per-character rules rather than a strict full-string match.If a generated example appears incorrect, the first step is to review the requestSchema and responseSchema objects in the preview output and compare them against the original WSDL/XSD source to verify that all constraints (pattern, maxLength, totalDigits, etc.) were correctly interpreted.
OnboardingDraftSuggestionService: Provides initial suggestions for API configuration.SoapMessageMapper: Handles the conversion between JSON payloads and SOAP 1.1 envelopes.WsdlRestRouteHeuristics: Implements the logic for inferring REST routes from WSDL operations.ConstrainedStringSampler: Generates string examples that conform to XSD length and pattern facets.RegexExampleGenerator: Creates example strings that match a given regular expression.ContractPatternValidator: Provides the canonical implementation for validating values against XSD patterns.