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 CONTEXT_BATCH: &str = "batch";
105
106pub const CLI_ROOT_COMMAND: &str = "api";
108
109pub const CACHE_SUFFIX: &str = "cache";
111pub const FILE_EXT_JSON: &str = ".json";
112pub const FILE_EXT_YAML: &str = ".yaml";
113pub const FILE_EXT_BIN: &str = ".bin";
114pub const CACHE_FILE_SUFFIX: &str = "_cache.json";
115pub const CACHE_METADATA_FILENAME: &str = "cache_metadata.json";
116pub const CONFIG_FILENAME: &str = "config.toml";
117
118pub const DIR_CACHE: &str = ".cache";
120pub const DIR_RESPONSES: &str = "responses";
121pub const DIR_SPECS: &str = "specs";
122
123pub const SCHEMA_TYPE_STRING: &str = "string";
125pub const SCHEMA_TYPE_NUMBER: &str = "number";
126pub const SCHEMA_TYPE_INTEGER: &str = "integer";
127pub const SCHEMA_TYPE_BOOLEAN: &str = "boolean";
128pub const SCHEMA_TYPE_ARRAY: &str = "array";
129pub const SCHEMA_TYPE_OBJECT: &str = "object";
130
131pub const HTTP_METHOD_GET: &str = "GET";
133pub const HTTP_METHOD_POST: &str = "POST";
134pub const HTTP_METHOD_PUT: &str = "PUT";
135pub const HTTP_METHOD_DELETE: &str = "DELETE";
136pub const HTTP_METHOD_PATCH: &str = "PATCH";
137pub const HTTP_METHOD_HEAD: &str = "HEAD";
138pub const HTTP_METHOD_OPTIONS: &str = "OPTIONS";
139
140pub const PARAM_LOCATION_PATH: &str = "path";
142pub const PARAM_LOCATION_QUERY: &str = "query";
143pub const PARAM_LOCATION_HEADER: &str = "header";
144pub const PARAM_LOCATION_COOKIE: &str = "cookie";
145
146pub const SECURITY_TYPE_HTTP: &str = "http";
148pub const SECURITY_TYPE_APIKEY: &str = "apiKey";
149
150pub const SOURCE_ENV: &str = "env";
152pub const LOCATION_HEADER: &str = "header";
153
154pub const FIELD_DEPRECATED: &str = "deprecated";
156pub const FIELD_REQUIRED: &str = "required";
157pub const FIELD_READ_ONLY: &str = "readOnly";
158pub const FIELD_WRITE_ONLY: &str = "writeOnly";
159pub const FIELD_NULLABLE: &str = "nullable";
160pub const FIELD_UNIQUE_ITEMS: &str = "uniqueItems";
161pub const FIELD_ALLOW_EMPTY_VALUE: &str = "allowEmptyValue";
162pub const FIELD_EXPLODE: &str = "explode";
163pub const FIELD_ALLOW_RESERVED: &str = "allowReserved";
164pub const FIELD_EXCLUSIVE_MINIMUM: &str = "exclusiveMinimum";
165pub const FIELD_EXCLUSIVE_MAXIMUM: &str = "exclusiveMaximum";
166
167pub const COMPONENT_SCHEMAS: &str = "schemas";
169pub const COMPONENT_RESPONSES: &str = "responses";
170pub const COMPONENT_EXAMPLES: &str = "examples";
171pub const COMPONENT_PARAMETERS: &str = "parameters";
172pub const COMPONENT_REQUEST_BODIES: &str = "requestBodies";
173pub const COMPONENT_HEADERS: &str = "headers";
174pub const COMPONENT_SECURITY_SCHEMES: &str = "securitySchemes";
175pub const COMPONENT_LINKS: &str = "links";
176pub const COMPONENT_CALLBACKS: &str = "callbacks";
177pub const COMPONENT_COMPONENTS: &str = "components";
178
179#[must_use]
181pub fn is_auth_header(name: &str) -> bool {
182 matches!(
183 name.to_lowercase().as_str(),
184 "authorization"
185 | "proxy-authorization"
186 | "x-api-key"
187 | "x-api-token"
188 | "x-auth-token"
189 | "api-key"
190 | "token"
191 | "bearer"
192 | "cookie"
193 )
194}
195
196#[must_use]
198pub fn is_json_content_type(content_type: &str) -> bool {
199 content_type.contains(CONTENT_TYPE_IDENTIFIER_JSON)
200}
201
202#[must_use]
204pub fn is_supported_content_type(content_type: &str) -> bool {
205 let ct = content_type.to_lowercase();
206 ct.contains(CONTENT_TYPE_IDENTIFIER_JSON)
207 || ct.contains(CONTENT_TYPE_IDENTIFIER_YAML)
208 || ct.contains(CONTENT_TYPE_IDENTIFIER_TEXT)
209}