import convertFromSchema from "./schema";
import InvalidInputError from "../errors/invalid-input-error";
const convertParameterSchema = ({ description }, schema, options) => {
    const jsonSchema = convertFromSchema(schema || {}, options);
    if (description) {
        jsonSchema.description = description;
    }
    return jsonSchema;
};
const convertFromContents = (parameter, options) => {
    const schemas = {};
    for (const mime in parameter.content) {
        schemas[mime] = convertParameterSchema(parameter, parameter.content[mime].schema, options);
    }
    return schemas;
};
const isResponseObject = (parameter) => {
    return Boolean(parameter) && "content" in parameter && Boolean(parameter.content);
};
// Convert from OpenAPI 3.0 `ParameterObject` to JSON schema v4
const convertFromParameter = (parameter, options) => {
    if ("schema" in parameter && parameter.schema) {
        return convertParameterSchema(parameter, parameter.schema, options);
    }
    if (isResponseObject(parameter)) {
        return convertFromContents(parameter, options);
    }
    if (options.strictMode) {
        throw new InvalidInputError("OpenAPI parameter must have either a 'schema' or a 'content' property");
    }
    return convertParameterSchema(parameter, {}, options);
};
export default convertFromParameter;
//# sourceMappingURL=parameter.js.map