001package org.hl7.fhir.r5.openapi;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r5
006 * %%
007 * Copyright (C) 2014 - 2019 Health Level 7
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024import com.google.gson.JsonObject;
025
026public class ParameterWriter extends BaseWriter {
027
028  public enum ParameterLocation {
029    query, header, path, cookie;
030  }
031  public enum ParameterStyle {
032    matrix, label, form, simple, spaceDelimited, pipeDelimited, deepObject;
033  }
034
035  public ParameterWriter(JsonObject object) {
036    super(object);
037  }
038
039  public ParameterWriter in(ParameterLocation value) {
040    object.addProperty("in", value.toString());
041    return this;            
042  }
043  
044  public ParameterWriter name(String value) {
045    object.addProperty("name", value);
046    return this;            
047  }
048  
049  public ParameterWriter allowEmptyValue() {
050    object.addProperty("allowEmptyValue", true);
051    return this;            
052  }
053  
054  public ParameterWriter description(String value) {
055    if (value != null)
056      object.addProperty("description", value);
057    return this;            
058  }
059  
060  public ParameterWriter required(boolean value) {
061    object.addProperty("required", value);
062    return this;            
063  }
064  
065  public ParameterWriter deprecated(boolean value) {
066    object.addProperty("deprecated", value);
067    return this;            
068  }
069  
070  public ParameterWriter allowEmptyValue(boolean value) {
071    object.addProperty("allowEmptyValue", value);
072    return this;            
073  }
074  
075
076  public ParameterWriter style(ParameterStyle value) {
077    object.addProperty("style", value.toString());
078    return this;            
079  }
080  
081  
082  public ParameterWriter explode(boolean value) {
083    object.addProperty("explode", value);
084    return this;            
085  }
086  
087  public ParameterWriter allowReserved(boolean value) {
088    object.addProperty("allowReserved", value);
089    return this;            
090  }
091    
092
093  public ParameterWriter schema(JsonObject jsonSchema) {
094    object.add("schema", jsonSchema);
095    return this;
096  }
097  
098  public SchemaWriter schema() {
099    JsonObject so = new JsonObject();
100    object.add("schema", so);
101    return new SchemaWriter(so);
102  }
103  
104  public ParameterWriter schemaRef(String name, String uri) {
105    JsonObject schema = new JsonObject();
106    schema.addProperty("$ref", uri);
107    object.add("schema", schema);
108    return this;
109  }
110  
111
112  public ParameterWriter example(JsonObject example) {
113    object.add("example", example);
114    return this;
115  }
116  
117}