var contact = new Contact({ phone: request.phone, status: request.status }); // Convert the Model instance to a simple object using Model's 'toObject' function // to prevent weirdness like infinite looping... var upsertData = contact.toObject(); // Delete the _id property, otherwise Mongo will return a "Mod on _id not allowed" error delete upsertData._id; // Do the upsert, which works like this: If no Contact document exists with // _id = contact.id, then create a new doc using upsertData. // Otherwise, update the existing doc with upsertData Contact.update({_id: contact.id}, upsertData, {upsert: true}, function(err{...});
/** * Determines title for definition. If title is present, it is used, definitionName is returned otherwise. * * @param params params object for this definition * @return Definition title - value from title tag if present, definitionName otherwise */ private String determineDefinitionTitle(Parameters params) { if (params.model.getTitle() != null) { return params.model.getTitle(); } else { return params.definitionName; } }
OperationHelper.doWithRetry(5, new Operation() { @Override public void doIt() { //do some stuff } @Override public void handleException(Exception cause) { //recover from the Exception } });
@Override public void apply(Swagger swagger) { if (swagger.getDefinitions() != null) { swagger.setDefinitions(new TreeMap<>(swagger.getDefinitions())); } if (swagger.getPaths() != null) { swagger.setPaths(new TreeMap<>(swagger.getPaths())); } } }
@Override public void apply(Swagger swagger) { ApiKeyAuthDefinition authorization = new ApiKeyAuthDefinition("Authorization", In.HEADER); authorization.setVendorExtension("x-amazon-apigateway-authtype", authType); swagger.securityDefinition(SECURITY_SCHEME_NAME, authorization); for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { operation.addSecurity(SECURITY_SCHEME_NAME, Collections.emptyList()); } } } }
@Override public void apply(Swagger swagger) { Map<String, Object> extensions = defaultExtensions(); for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { operation.setVendorExtension("x-amazon-apigateway-integration", extensions); } } }
private static Map<String, Property> getPropertiesForComposedModel(ComposedModel model, Map<String, Model> definitions) { //TODO: Unused method, make sure this is never used and then remove it. Map<String, Property> combinedProperties; if (model.getParent() instanceof RefModel) { Map<String, Property> parentProperties = definitions.get(((RefModel) model.getParent()).getSimpleRef()).getProperties(); if (parentProperties == null) { return null; } else { combinedProperties = new LinkedHashMap<>(parentProperties); } } else { combinedProperties = new LinkedHashMap<>(model.getParent().getProperties()); } Map<String, Property> childProperties; if (model.getChild() instanceof RefModel) { childProperties = definitions.get(((RefModel) model.getChild()).getSimpleRef()).getProperties(); } else { childProperties = model.getChild().getProperties(); } if (childProperties != null) { combinedProperties.putAll(childProperties); } return combinedProperties; }
private MarkupDocBuilder applyPathsDocument() { return pathsDocument.apply( context.createMarkupDocBuilder(), PathsDocument.parameters(context.getSwagger().getPaths())); }
ResponseComponent(Swagger2MarkupConverter.Context context, DocumentResolver definitionDocumentResolver) { super(context); this.definitions = context.getSwagger().getDefinitions(); this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null"); this.tableComponent = new TableComponent(context); }
/** * Returns an unique id for the operation.<br> * Use {@code <operation id>}, then {@code <operation path> lowercase(<operation method>)} if operation id is not set. * * @return operation unique id */ public String getId() { String id = operation.getOperationId(); if (id == null) id = getPath() + " " + getMethod().toString().toLowerCase(); return id; }
private static Object generateExampleForArrayModel(ArrayModel model, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder, Map<String, Integer> refStack) { if (model.getExample() != null) { return model.getExample(); } else if (model.getProperties() != null) { return new Object[]{exampleMapForProperties(model.getProperties(), definitions, definitionDocumentResolver, markupDocBuilder, refStack)}; } else { Property itemProperty = model.getItems(); return getExample(itemProperty, definitions, definitionDocumentResolver, markupDocBuilder, refStack); } }
private String mapToString(Tag tag) { String name = tag.getName(); String description = tag.getDescription(); if (isNotBlank(description)) { return name + COLON + description; } else { return name; } }
/** * Returns the display title for an operation * * @return the operation title */ public String getTitle() { String operationName = operation.getSummary(); if (isBlank(operationName)) { operationName = getMethod().toString() + " " + getPath(); } return operationName; }
private MarkupDocBuilder applySecurityDocument() { return securityDocument.apply( context.createMarkupDocBuilder(), SecurityDocument.parameters(context.getSwagger().getSecurityDefinitions())); }
@Override public void apply(Swagger swagger) { swagger.setVendorExtension("x-generated-at", Instant.now().toString()); } }
@Before public void setUp() { operation = new PathOperation(HttpMethod.GET, "/test", new Operation()); }
private MarkupDocBuilder applyDefinitionsDocument() { return definitionsDocument.apply( context.createMarkupDocBuilder(), DefinitionsDocument.parameters(context.getSwagger().getDefinitions())); }
Account account = new Account(); Contact contact = new Contact(); account.addToContact(contact); em.persist(account); em.flush(); assertNotNull(account.getId()); assertNotNull(account.getContacts().get(0).getId()); assertEquals(1, account.getContacts().size()); account.removeFromContact(contact); em.merge(account); em.flush(); assertEquals(0, account.getContacts().size());
@Before public void setUp() { operation = new PathOperation(HttpMethod.GET, "/test", new Operation()); }