aperture_cli/
constants.rs1pub const HEADER_ACCEPT: &str = "Accept";
10pub const HEADER_AUTHORIZATION: &str = "Authorization";
11pub const HEADER_CONTENT_TYPE: &str = "Content-Type";
12pub const HEADER_PROXY_AUTHORIZATION: &str = "Proxy-Authorization";
13pub const HEADER_X_API_KEY: &str = "X-Api-Key";
14pub const HEADER_X_API_TOKEN: &str = "X-Api-Token";
15pub const HEADER_X_AUTH_TOKEN: &str = "X-Auth-Token";
16pub const HEADER_API_KEY: &str = "Api-Key";
17pub const HEADER_TOKEN: &str = "Token";
18pub const HEADER_BEARER: &str = "Bearer";
19pub const HEADER_COOKIE: &str = "Cookie";
20
21pub const HEADER_AUTHORIZATION_LC: &str = "authorization";
23pub const HEADER_CONTENT_TYPE_LC: &str = "content-type";
24
25pub const HEADER_PREFIX_X_AUTH: &str = "x-auth-";
27pub const HEADER_PREFIX_X_API: &str = "x-api-";
28
29pub const CONTENT_TYPE_JSON: &str = "application/json";
31pub const CONTENT_TYPE_YAML: &str = "application/yaml";
32pub const CONTENT_TYPE_XML: &str = "application/xml";
33pub const CONTENT_TYPE_FORM: &str = "application/x-www-form-urlencoded";
34pub const CONTENT_TYPE_MULTIPART: &str = "multipart/form-data";
35pub const CONTENT_TYPE_TEXT: &str = "text/plain";
36pub const CONTENT_TYPE_PDF: &str = "application/pdf";
37pub const CONTENT_TYPE_GRAPHQL: &str = "application/graphql";
38pub const CONTENT_TYPE_OCTET_STREAM: &str = "application/octet-stream";
39pub const CONTENT_TYPE_NDJSON: &str = "application/x-ndjson";
40pub const CONTENT_TYPE_TEXT_XML: &str = "text/xml";
41pub const CONTENT_TYPE_CSV: &str = "text/csv";
42
43pub const CONTENT_TYPE_PREFIX_IMAGE: &str = "image/";
45pub const CONTENT_TYPE_IDENTIFIER_JSON: &str = "json";
46pub const CONTENT_TYPE_IDENTIFIER_YAML: &str = "yaml";
47pub const CONTENT_TYPE_IDENTIFIER_TEXT: &str = "text";
48
49pub const EXT_APERTURE_SECRET: &str = "x-aperture-secret";
51pub const EXT_KEY_SOURCE: &str = "source";
52pub const EXT_KEY_NAME: &str = "name";
53pub const EXT_APERTURE_PAGINATION: &str = "x-aperture-pagination";
54
55pub const PAGINATION_STRATEGY_CURSOR: &str = "cursor";
57pub const PAGINATION_STRATEGY_OFFSET: &str = "offset";
58pub const PAGINATION_STRATEGY_LINK_HEADER: &str = "link-header";
59pub const PAGINATION_STRATEGY_NONE: &str = "none";
60
61pub const PAGINATION_CURSOR_FIELDS: &[&str] = &[
64 "next_cursor",
65 "after",
66 "continuation_token",
67 "next_page_token",
68 "nextCursor",
69 "nextPageToken",
70 "cursor",
71];
72
73pub const PAGINATION_PAGE_PARAMS: &[&str] = &["page", "offset", "skip"];
75
76pub const PAGINATION_LIMIT_PARAMS: &[&str] = &["limit", "per_page", "page_size", "pageSize"];
78
79pub const HEADER_LINK: &str = "link";
81
82pub const AUTH_SCHEME_BEARER: &str = "bearer";
84pub const AUTH_SCHEME_BASIC: &str = "basic";
85pub const AUTH_SCHEME_APIKEY: &str = "apiKey";
86pub const AUTH_SCHEME_OAUTH2: &str = "oauth2";
87pub const AUTH_SCHEME_OPENID: &str = "openidconnect";
88
89pub const ENV_APERTURE_CONFIG_DIR: &str = "APERTURE_CONFIG_DIR";
91pub const ENV_APERTURE_BASE_URL: &str = "APERTURE_BASE_URL";
92pub const ENV_APERTURE_ENV: &str = "APERTURE_ENV";
93
94pub const EMPTY_RESPONSE: &str = "(empty response)";
96pub const EMPTY_ARRAY: &str = "(empty array)";
97pub const NULL_VALUE: &str = "null";
98
99pub const ERR_API_CREDENTIALS: &str =
101 "Check your API credentials and authentication configuration.";
102pub const ERR_PERMISSION_DENIED: &str =
103 "Your credentials may be valid but lack permission for this operation.";
104pub const ERR_ENDPOINT_NOT_FOUND: &str = "Check that the API endpoint and parameters are correct.";
105pub const ERR_RATE_LIMITED: &str = "You're making requests too quickly. Wait before trying again.";
106pub const ERR_SERVER_ERROR: &str = "The API server is experiencing issues. Try again later.";
107pub const ERR_CONNECTION: &str = "Check that the API server is running and accessible.";
108pub const ERR_TIMEOUT: &str = "The API server may be slow or unresponsive. Try again later.";
109
110pub const ERR_FILE_NOT_FOUND: &str = "Check that the file path is correct and the file exists.";
112pub const ERR_PERMISSION: &str = "Check file permissions or run with appropriate privileges.";
113
114pub const ERR_YAML_SYNTAX: &str = "Check that your OpenAPI specification is valid YAML syntax.";
116pub const ERR_JSON_SYNTAX: &str = "Check that your request body or response contains valid JSON.";
117pub const ERR_TOML_SYNTAX: &str = "Check that your configuration file is valid TOML syntax.";
118pub const ERR_OPENAPI_FORMAT: &str =
119 "Check that your OpenAPI specification follows the required format.";
120
121pub const MSG_USE_HELP: &str = "Use --help to see available commands.";
123pub const MSG_USE_CONFIG_LIST: &str = "Use 'aperture config list' to see available specifications.";
124pub const MSG_WARNING_PREFIX: &str = "Warning:";
125
126pub const DEFAULT_GROUP: &str = "default";
128pub const DEFAULT_CACHE_TTL: u64 = 300;
129pub const DEFAULT_OPERATION_NAME: &str = "unnamed";
130
131pub const SUCCESS_STATUS_CODES: [&str; 3] = ["200", "201", "204"];
134
135pub const CONTEXT_BATCH: &str = "batch";
137
138pub const CLI_ROOT_COMMAND: &str = "api";
140
141pub const CACHE_SUFFIX: &str = "cache";
143pub const FILE_EXT_JSON: &str = ".json";
144pub const FILE_EXT_YAML: &str = ".yaml";
145pub const FILE_EXT_BIN: &str = ".bin";
146pub const CACHE_FILE_SUFFIX: &str = "_cache.json";
147pub const CACHE_METADATA_FILENAME: &str = "cache_metadata.json";
148pub const CONFIG_FILENAME: &str = "config.toml";
149
150pub const DIR_CACHE: &str = ".cache";
152pub const DIR_RESPONSES: &str = "responses";
153pub const DIR_SPECS: &str = "specs";
154
155pub const SCHEMA_TYPE_STRING: &str = "string";
157pub const SCHEMA_TYPE_NUMBER: &str = "number";
158pub const SCHEMA_TYPE_INTEGER: &str = "integer";
159pub const SCHEMA_TYPE_BOOLEAN: &str = "boolean";
160pub const SCHEMA_TYPE_ARRAY: &str = "array";
161pub const SCHEMA_TYPE_OBJECT: &str = "object";
162
163pub const HTTP_METHOD_GET: &str = "GET";
165pub const HTTP_METHOD_POST: &str = "POST";
166pub const HTTP_METHOD_PUT: &str = "PUT";
167pub const HTTP_METHOD_DELETE: &str = "DELETE";
168pub const HTTP_METHOD_PATCH: &str = "PATCH";
169pub const HTTP_METHOD_HEAD: &str = "HEAD";
170pub const HTTP_METHOD_OPTIONS: &str = "OPTIONS";
171
172pub const PARAM_LOCATION_PATH: &str = "path";
174pub const PARAM_LOCATION_QUERY: &str = "query";
175pub const PARAM_LOCATION_HEADER: &str = "header";
176pub const PARAM_LOCATION_COOKIE: &str = "cookie";
177
178pub const SECURITY_TYPE_HTTP: &str = "http";
180pub const SECURITY_TYPE_APIKEY: &str = "apiKey";
181
182pub const SOURCE_ENV: &str = "env";
184pub const LOCATION_HEADER: &str = "header";
185
186pub const FIELD_DEPRECATED: &str = "deprecated";
188pub const FIELD_REQUIRED: &str = "required";
189pub const FIELD_READ_ONLY: &str = "readOnly";
190pub const FIELD_WRITE_ONLY: &str = "writeOnly";
191pub const FIELD_NULLABLE: &str = "nullable";
192pub const FIELD_UNIQUE_ITEMS: &str = "uniqueItems";
193pub const FIELD_ALLOW_EMPTY_VALUE: &str = "allowEmptyValue";
194pub const FIELD_EXPLODE: &str = "explode";
195pub const FIELD_ALLOW_RESERVED: &str = "allowReserved";
196pub const FIELD_EXCLUSIVE_MINIMUM: &str = "exclusiveMinimum";
197pub const FIELD_EXCLUSIVE_MAXIMUM: &str = "exclusiveMaximum";
198
199pub const COMPONENT_SCHEMAS: &str = "schemas";
201pub const COMPONENT_RESPONSES: &str = "responses";
202pub const COMPONENT_EXAMPLES: &str = "examples";
203pub const COMPONENT_PARAMETERS: &str = "parameters";
204pub const COMPONENT_REQUEST_BODIES: &str = "requestBodies";
205pub const COMPONENT_HEADERS: &str = "headers";
206pub const COMPONENT_SECURITY_SCHEMES: &str = "securitySchemes";
207pub const COMPONENT_LINKS: &str = "links";
208pub const COMPONENT_CALLBACKS: &str = "callbacks";
209pub const COMPONENT_COMPONENTS: &str = "components";
210
211#[must_use]
213pub fn is_auth_header(name: &str) -> bool {
214 matches!(
215 name.to_lowercase().as_str(),
216 "authorization"
217 | "proxy-authorization"
218 | "x-api-key"
219 | "x-api-token"
220 | "x-auth-token"
221 | "api-key"
222 | "token"
223 | "bearer"
224 | "cookie"
225 )
226}
227
228#[must_use]
230pub fn is_json_content_type(content_type: &str) -> bool {
231 content_type.contains(CONTENT_TYPE_IDENTIFIER_JSON)
232}
233
234#[must_use]
236pub fn is_supported_content_type(content_type: &str) -> bool {
237 let ct = content_type.to_lowercase();
238 ct.contains(CONTENT_TYPE_IDENTIFIER_JSON)
239 || ct.contains(CONTENT_TYPE_IDENTIFIER_YAML)
240 || ct.contains(CONTENT_TYPE_IDENTIFIER_TEXT)
241}