no-host-path-templating
Overview
This rule belongs to the swagger-v2-syntax-validation
ruleset and states that:
In Swagger 2.0, the host
field is used to specify the hostname (and optionally the port number) where the API is hosted. The violation occurs when path templating, which is the use of variables within the host field, is detected. Path templating is not supported in the host
field according to the Swagger 2.0 specification.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Error |
Message | Path templating found in the host which is not supported |
Code | SWAGGER20SYNTAX_V001 |
Type | Validation |
Rule System | Syntax |
Broad Category | API Server |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | swagger2 swagger syntax validation host url path templating |
Suggested Fixes
- Remove path templating from the host: Review the
host
field in your Swagger 2.0 specification and ensure that it contains a static hostname (and optionally a port number) without any variables or placeholders. Thehost
field should be a fixed value that represents the actual host where the API is hosted. - Use path parameters instead: If you need to include dynamic elements in the host field, consider using path parameters in the
paths
section of your Swagger specification instead. Path parameters allow you to define variables within the path of individual API endpoints, rather than in thehost
field.