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";
53
54pub const AUTH_SCHEME_BEARER: &str = "bearer";
56pub const AUTH_SCHEME_BASIC: &str = "basic";
57pub const AUTH_SCHEME_APIKEY: &str = "apiKey";
58pub const AUTH_SCHEME_OAUTH2: &str = "oauth2";
59pub const AUTH_SCHEME_OPENID: &str = "openidconnect";
60
61pub const ENV_APERTURE_CONFIG_DIR: &str = "APERTURE_CONFIG_DIR";
63pub const ENV_APERTURE_BASE_URL: &str = "APERTURE_BASE_URL";
64pub const ENV_APERTURE_ENV: &str = "APERTURE_ENV";
65
66pub const EMPTY_RESPONSE: &str = "(empty response)";
68pub const EMPTY_ARRAY: &str = "(empty array)";
69pub const NULL_VALUE: &str = "null";
70
71pub const ERR_API_CREDENTIALS: &str =
73 "Check your API credentials and authentication configuration.";
74pub const ERR_PERMISSION_DENIED: &str =
75 "Your credentials may be valid but lack permission for this operation.";
76pub const ERR_ENDPOINT_NOT_FOUND: &str = "Check that the API endpoint and parameters are correct.";
77pub const ERR_RATE_LIMITED: &str = "You're making requests too quickly. Wait before trying again.";
78pub const ERR_SERVER_ERROR: &str = "The API server is experiencing issues. Try again later.";
79pub const ERR_CONNECTION: &str = "Check that the API server is running and accessible.";
80pub const ERR_TIMEOUT: &str = "The API server may be slow or unresponsive. Try again later.";
81
82pub const ERR_FILE_NOT_FOUND: &str = "Check that the file path is correct and the file exists.";
84pub const ERR_PERMISSION: &str = "Check file permissions or run with appropriate privileges.";
85
86pub const ERR_YAML_SYNTAX: &str = "Check that your OpenAPI specification is valid YAML syntax.";
88pub const ERR_JSON_SYNTAX: &str = "Check that your request body or response contains valid JSON.";
89pub const ERR_TOML_SYNTAX: &str = "Check that your configuration file is valid TOML syntax.";
90pub const ERR_OPENAPI_FORMAT: &str =
91 "Check that your OpenAPI specification follows the required format.";
92
93pub const MSG_USE_HELP: &str = "Use --help to see available commands.";
95pub const MSG_USE_CONFIG_LIST: &str = "Use 'aperture config list' to see available specifications.";
96pub const MSG_WARNING_PREFIX: &str = "Warning:";
97
98pub const DEFAULT_GROUP: &str = "default";
100pub const DEFAULT_CACHE_TTL: u64 = 300;
101pub const DEFAULT_OPERATION_NAME: &str = "unnamed";
102
103pub const SUCCESS_STATUS_CODES: [&str; 3] = ["200", "201", "204"];
106
107pub const CONTEXT_BATCH: &str = "batch";
109
110pub const CLI_ROOT_COMMAND: &str = "api";
112
113pub const CACHE_SUFFIX: &str = "cache";
115pub const FILE_EXT_JSON: &str = ".json";
116pub const FILE_EXT_YAML: &str = ".yaml";
117pub const FILE_EXT_BIN: &str = ".bin";
118pub const CACHE_FILE_SUFFIX: &str = "_cache.json";
119pub const CACHE_METADATA_FILENAME: &str = "cache_metadata.json";
120pub const CONFIG_FILENAME: &str = "config.toml";
121
122pub const DIR_CACHE: &str = ".cache";
124pub const DIR_RESPONSES: &str = "responses";
125pub const DIR_SPECS: &str = "specs";
126
127pub const SCHEMA_TYPE_STRING: &str = "string";
129pub const SCHEMA_TYPE_NUMBER: &str = "number";
130pub const SCHEMA_TYPE_INTEGER: &str = "integer";
131pub const SCHEMA_TYPE_BOOLEAN: &str = "boolean";
132pub const SCHEMA_TYPE_ARRAY: &str = "array";
133pub const SCHEMA_TYPE_OBJECT: &str = "object";
134
135pub const HTTP_METHOD_GET: &str = "GET";
137pub const HTTP_METHOD_POST: &str = "POST";
138pub const HTTP_METHOD_PUT: &str = "PUT";
139pub const HTTP_METHOD_DELETE: &str = "DELETE";
140pub const HTTP_METHOD_PATCH: &str = "PATCH";
141pub const HTTP_METHOD_HEAD: &str = "HEAD";
142pub const HTTP_METHOD_OPTIONS: &str = "OPTIONS";
143
144pub const PARAM_LOCATION_PATH: &str = "path";
146pub const PARAM_LOCATION_QUERY: &str = "query";
147pub const PARAM_LOCATION_HEADER: &str = "header";
148pub const PARAM_LOCATION_COOKIE: &str = "cookie";
149
150pub const SECURITY_TYPE_HTTP: &str = "http";
152pub const SECURITY_TYPE_APIKEY: &str = "apiKey";
153
154pub const SOURCE_ENV: &str = "env";
156pub const LOCATION_HEADER: &str = "header";
157
158pub const FIELD_DEPRECATED: &str = "deprecated";
160pub const FIELD_REQUIRED: &str = "required";
161pub const FIELD_READ_ONLY: &str = "readOnly";
162pub const FIELD_WRITE_ONLY: &str = "writeOnly";
163pub const FIELD_NULLABLE: &str = "nullable";
164pub const FIELD_UNIQUE_ITEMS: &str = "uniqueItems";
165pub const FIELD_ALLOW_EMPTY_VALUE: &str = "allowEmptyValue";
166pub const FIELD_EXPLODE: &str = "explode";
167pub const FIELD_ALLOW_RESERVED: &str = "allowReserved";
168pub const FIELD_EXCLUSIVE_MINIMUM: &str = "exclusiveMinimum";
169pub const FIELD_EXCLUSIVE_MAXIMUM: &str = "exclusiveMaximum";
170
171pub const COMPONENT_SCHEMAS: &str = "schemas";
173pub const COMPONENT_RESPONSES: &str = "responses";
174pub const COMPONENT_EXAMPLES: &str = "examples";
175pub const COMPONENT_PARAMETERS: &str = "parameters";
176pub const COMPONENT_REQUEST_BODIES: &str = "requestBodies";
177pub const COMPONENT_HEADERS: &str = "headers";
178pub const COMPONENT_SECURITY_SCHEMES: &str = "securitySchemes";
179pub const COMPONENT_LINKS: &str = "links";
180pub const COMPONENT_CALLBACKS: &str = "callbacks";
181pub const COMPONENT_COMPONENTS: &str = "components";
182
183#[must_use]
185pub fn is_auth_header(name: &str) -> bool {
186 matches!(
187 name.to_lowercase().as_str(),
188 "authorization"
189 | "proxy-authorization"
190 | "x-api-key"
191 | "x-api-token"
192 | "x-auth-token"
193 | "api-key"
194 | "token"
195 | "bearer"
196 | "cookie"
197 )
198}
199
200#[must_use]
202pub fn is_json_content_type(content_type: &str) -> bool {
203 content_type.contains(CONTENT_TYPE_IDENTIFIER_JSON)
204}
205
206#[must_use]
208pub fn is_supported_content_type(content_type: &str) -> bool {
209 let ct = content_type.to_lowercase();
210 ct.contains(CONTENT_TYPE_IDENTIFIER_JSON)
211 || ct.contains(CONTENT_TYPE_IDENTIFIER_YAML)
212 || ct.contains(CONTENT_TYPE_IDENTIFIER_TEXT)
213}