001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.oapi; 014 015import org.apache.juneau.*; 016import org.apache.juneau.annotation.*; 017import org.apache.juneau.parser.*; 018import org.apache.juneau.uon.*; 019 020/** 021 * OpenAPI part parser. 022 * 023 * <ul class='seealso'> 024 * <li class='link'>{@doc juneau-marshall.OpenApiDetails.Parsers} 025 * </ul> 026 */ 027@ConfigurableContext 028public class OpenApiParser extends UonParser { 029 030 //------------------------------------------------------------------------------------------------------------------- 031 // Configurable properties 032 //------------------------------------------------------------------------------------------------------------------- 033 034 static final String PREFIX = "OpenApiParser"; 035 036 //------------------------------------------------------------------------------------------------------------------- 037 // Predefined instances 038 //------------------------------------------------------------------------------------------------------------------- 039 040 /** Reusable instance of {@link OpenApiParser}. */ 041 public static final OpenApiParser DEFAULT = new OpenApiParser(PropertyStore.DEFAULT); 042 043 044 //------------------------------------------------------------------------------------------------------------------- 045 // Instance 046 //------------------------------------------------------------------------------------------------------------------- 047 048 /** 049 * Constructor. 050 * 051 * @param ps The property store containing all the settings for this object. 052 */ 053 public OpenApiParser(PropertyStore ps) { 054 this(ps, "text/openapi"); 055 } 056 057 /** 058 * Constructor. 059 * 060 * @param ps 061 * The property store containing all the settings for this object. 062 * @param consumes 063 * The list of media types that this parser consumes (e.g. <js>"application/json"</js>, <js>"*​/json"</js>). 064 */ 065 public OpenApiParser(PropertyStore ps, String...consumes) { 066 super(ps, consumes); 067 } 068 069 @Override /* Context */ 070 public OpenApiParserBuilder builder() { 071 return new OpenApiParserBuilder(getPropertyStore()); 072 } 073 074 /** 075 * Instantiates a new clean-slate {@link OpenApiParserBuilder} object. 076 * 077 * <p> 078 * This is equivalent to simply calling <code><jk>new</jk> UonPartParserBuilder()</code>. 079 * 080 * <p> 081 * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 082 * the settings of the object called on. 083 * 084 * @return A new {@link OpenApiParserBuilder} object. 085 */ 086 public static OpenApiParserBuilder create() { 087 return new OpenApiParserBuilder(); 088 } 089 090 //------------------------------------------------------------------------------------------------------------------- 091 // Entry point methods 092 //------------------------------------------------------------------------------------------------------------------- 093 094 @Override 095 public OpenApiParserSession createSession() { 096 return new OpenApiParserSession(this, ParserSessionArgs.DEFAULT); 097 } 098 099 @Override 100 public OpenApiParserSession createPartSession(ParserSessionArgs args) { 101 return new OpenApiParserSession(this, args); 102 } 103 104 //----------------------------------------------------------------------------------------------------------------- 105 // Other methods 106 //----------------------------------------------------------------------------------------------------------------- 107 108 @Override /* Context */ 109 public ObjectMap toMap() { 110 return super.toMap() 111 .append("OpenApiParser", new DefaultFilteringObjectMap() 112 ); 113 } 114}